summaryrefslogtreecommitdiff
path: root/tests/unittests/test_cli.py
blob: 8268cd5ed46c84e5aa21efb3e8df1f4421597e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import imp
import os
import six
import sys

from . import helpers as test_helpers
mock = test_helpers.mock

from cloudinit.cmd import main as cli


class TestCLI(test_helpers.FilesystemMockingTestCase):

    def setUp(self):
        super(TestCLI, self).setUp()
        self.stderr = six.StringIO()
        self.patchStdoutAndStderr(stderr=self.stderr)

    def _call_main(self, sysv_args=None):
        if not sysv_args:
            sysv_args = ['cloud-init']
        try:
            return cli.main(sysv_args=sysv_args)
        except SystemExit as e:
            return e.code

    def test_no_arguments_shows_usage(self):
        exit_code = self._call_main()
        self.assertIn('usage: cloud-init', self.stderr.getvalue())
        self.assertEqual(2, exit_code)

    def test_no_arguments_shows_error_message(self):
        exit_code = self._call_main()
        self.assertIn('cloud-init: error: too few arguments',
                      self.stderr.getvalue())
        self.assertEqual(2, exit_code)