示例#1
0
    def test_deprecated_tag_semver(self, capfd):
        """
        When the main function is given the `--tag-semver` option, the option
        should be used as the `--version-semver` option and a deprecation
        warning should be printed.
        """
        main([
            '--executable',
            'echo',
            '--version',
            '1.2.3',
            '--tag-semver',
            'test-image',
        ])

        assert_output_lines(capfd, [
            'tag test-image test-image:1.2.3',
            'tag test-image test-image:1.2',
            'tag test-image test-image:1',
            'push test-image:1.2.3',
            'push test-image:1.2',
            'push test-image:1',
        ], [('DEPRECATED: the --tag-semver option is deprecated and will be '
             'removed in the next release. Please use --version-semver '
             'instead')])
示例#2
0
    def test_version(self, capfd):
        """
        When the --version flag is used, the version is added to the image tag.
        """
        main(['--executable', 'echo', '--version', '1.2.3', 'test-image:abc'])

        assert_output_lines(capfd, [
            'tag test-image:abc test-image:1.2.3-abc',
            'push test-image:1.2.3-abc'
        ])
示例#3
0
    def test_args(self, capfd):
        """
        When the main function is given a set of common arguments, the script
        should be run as expected.
        """
        main([
            '--registry', 'registry.example.com:5000', '--executable', 'echo',
            'test-image:abc'
        ])

        assert_output_lines(capfd, [
            'tag test-image:abc registry.example.com:5000/test-image:abc',
            'push registry.example.com:5000/test-image:abc'
        ])
示例#4
0
    def test_executable_requires_argument(self, capfd):
        """
        When the main function is given the `--executable` option without an
        argument, an error should be raised.
        """
        with ExpectedException(SystemExit, MatchesStructure(code=Equals(2))):
            main(['--executable', '--', 'test-image'])

        out, err = capfd.readouterr()
        assert_that(out, Equals(''))
        assert_that(
            err,
            MatchesRegex(
                r'.*error: argument --executable: expected one argument$',
                re.DOTALL))
示例#5
0
    def test_many_tags(self, capfd):
        """
        When the main function is given multiple tag arguments in different
        ways, the tags should be correctly passed through to the runner.
        """
        main([
            '--tag', 'abc', 'def', '-t', 'ghi', '--executable', 'echo',
            'test-image:xyz'
        ])

        assert_output_lines(capfd, [
            'tag test-image:xyz test-image:abc',
            'tag test-image:xyz test-image:def',
            'tag test-image:xyz test-image:ghi', 'push test-image:abc',
            'push test-image:def', 'push test-image:ghi'
        ])
示例#6
0
    def test_semver_zero_requires_version_semver(self, capfd):
        """
        When the main function is given the `--semver-zero` option but no
        `--version-semver` option, it should exit with a return code of 2 and
        inform the user of the missing option.
        """
        with ExpectedException(SystemExit, MatchesStructure(code=Equals(2))):
            main(['--semver-zero', 'test-image:abc'])

        out, err = capfd.readouterr()
        assert_that(out, Equals(''))
        assert_that(
            err,
            MatchesRegex(
                r'.*error: the --semver-zero option requires --version-semver$',
                re.DOTALL))
示例#7
0
    def test_version_latest_requires_non_empty_version(self, capfd):
        """
        When the main function is given the `--version-latest` option and an
        empty `--version` option, it should exit with a return code of 2 and
        inform the user of the missing option.
        """
        with ExpectedException(SystemExit, MatchesStructure(code=Equals(2))):
            main(['--version-latest', '--version', '', 'test-image:abc'])

        out, err = capfd.readouterr()
        assert_that(out, Equals(''))
        assert_that(
            err,
            MatchesRegex(
                r'.*error: the --version-latest option requires --version$',
                re.DOTALL))
示例#8
0
    def test_semver_precision(self, capfd):
        """
        When the --semver-precision option is used, the semver versions are
        generated with the correct precision.
        """
        main([
            '--executable', 'echo', '--version', '1.2.3', '--version-semver',
            '--semver-precision', '2', 'test-image:abc'
        ])

        assert_output_lines(capfd, [
            'tag test-image:abc test-image:1.2.3-abc',
            'tag test-image:abc test-image:1.2-abc',
            'push test-image:1.2.3-abc',
            'push test-image:1.2-abc',
        ])
示例#9
0
    def test_semver_precision_default(self, capfd):
        """
        When the --version-semver flag is used, but the --semver-precision
        option is not, the semver precision should default to 1.
        """
        main([
            '--executable', 'echo', '--version', '1.2.3', '--version-semver',
            'test-image:abc'
        ])

        assert_output_lines(capfd, [
            'tag test-image:abc test-image:1.2.3-abc',
            'tag test-image:abc test-image:1.2-abc',
            'tag test-image:abc test-image:1-abc',
            'push test-image:1.2.3-abc',
            'push test-image:1.2-abc',
            'push test-image:1-abc',
        ])
示例#10
0
    def test_version_take_precedence_over_deprecated_tag_version(self, capfd):
        """
        When the main function is given the `--version` and `--tag-version`
        options, the `--version` value takes precedence over the
        `--tag-version` value.
        """
        main([
            '--executable',
            'echo',
            '--version',
            '1.2.3',
            '--tag-version',
            '4.5.6',
            'test-image',
        ])

        assert_output_lines(capfd, [
            'tag test-image test-image:1.2.3',
            'push test-image:1.2.3',
        ], [('DEPRECATED: the --tag-version option is deprecated and will be '
             'removed in the next release. Please use --version instead')])
示例#11
0
    def test_version_semver_requires_argument(self, capfd):
        """
        When the main function is given the `--version-semver` option without
        an argument, an error should be raised.
        """
        with ExpectedException(SystemExit, MatchesStructure(code=Equals(2))):
            main([
                '--version',
                '1.2.3',
                '--version-semver',
                '--semver-precision',
                '--',
                'test-image',
            ])

        out, err = capfd.readouterr()
        assert_that(out, Equals(''))
        assert_that(
            err,
            MatchesRegex(
                r'.*error: argument -P/--semver-precision: expected one argument$',
                re.DOTALL))
示例#12
0
    def test_image_required(self, capfd):
        """
        When the main function is given no image argument, it should exit with
        a return code of 2 and inform the user of the missing argument.
        """
        with ExpectedException(SystemExit, MatchesStructure(code=Equals(2))):
            main(['--tag', 'abc'])

        out, err = capfd.readouterr()
        assert_that(out, Equals(''))

        # More useful error message added to argparse in Python 3
        if sys.version_info >= (3, ):
            # Use re.DOTALL so that '.*' also matches newlines
            assert_that(
                err,
                MatchesRegex(
                    r'.*error: the following arguments are required: image$',
                    re.DOTALL))
        else:
            assert_that(
                err, MatchesRegex(r'.*error: too few arguments$', re.DOTALL))