예제 #1
0
def test_args_target(mocker):
    mocker.patch.object(sys, 'argv', ['cekit',
                                      'build',
                                      '--target',
                                      'foo'])

    assert Cekit().parse().args.target == 'foo'
예제 #2
0
def test_args_overrides_exclusiver(mocker):
    mocker.patch.object(
        sys, 'argv',
        ['cekit', 'build', 'overrides', 'bar', '--overrides-file', 'foo'])

    with pytest.raises(SystemExit):
        Cekit().parse()
예제 #3
0
def test_args_workd_dir(mocker):
    mocker.patch.object(sys, 'argv', ['cekit',
                                      'generate',
                                      '--work-dir',
                                      'foo'])

    assert Cekit().parse().args.work_dir == 'foo'
예제 #4
0
def test_args_overrides_file(mocker):
    mocker.patch.object(sys, 'argv', ['cekit',
                                      'build',
                                      '--overrides-file',
                                      'foo'])

    assert Cekit().parse().args.overrides == ['foo']
예제 #5
0
def test_args_config(mocker):
    mocker.patch.object(sys, 'argv', ['cekit',
                                      '--config',
                                      'whatever',
                                      'generate'])

    assert Cekit().parse().args.config == 'whatever'
예제 #6
0
def test_args_osbs_user(mocker):
    mocker.patch.object(sys, 'argv', ['cekit',
                                      'build',
                                      '--build-engine',
                                      'osbs',
                                      '--build-osbs-user',
                                      'USER'])

    assert Cekit().parse().args.build_osbs_user == 'USER'
예제 #7
0
def test_image_override_help_template(mocker, tmpdir):
    """Test that help_template defined in image.yaml is used for
       generating help.md"""

    help_template = os.path.join(str(tmpdir), "help.jinja")
    with open(help_template, "w") as fd:
        fd.write(template_teststr)

    config = setup_config(tmpdir, "")
    my_image_descriptor = image_descriptor.copy()
    my_image_descriptor['help'] = {'template': help_template}
    mocker.patch.object(sys, 'argv',
                        ['cekit', '-v', '--config', config, 'generate'])

    with Chdir(str(tmpdir)):
        with open('image.yaml', 'w') as fd:
            yaml.dump(my_image_descriptor, fd, default_flow_style=False)
        c = Cekit().parse()
        c.configure()
        try:
            c.run()
        except SystemExit:
            pass
        with open("target/image/help.md", "r") as fd:
            contents = fd.read()
            assert contents.find(template_teststr) >= 0
예제 #8
0
def test_image_override_config_help_template(mocker, tmpdir):
    """Test that help_template defined in image.yaml overrides help_template
       defined in the config"""

    help_template1 = os.path.join(str(tmpdir), "help1.jinja")
    with open(help_template1, "w") as fd:
        fd.write("1")
    config = setup_config(tmpdir,
                          "[doc]\nhelp_template = {}".format(help_template1))

    help_template2 = os.path.join(str(tmpdir), "help2.jinja")
    with open(help_template2, "w") as fd:
        fd.write("2")
    my_image_descriptor = image_descriptor.copy()
    my_image_descriptor['help'] = {'template': help_template2}

    mocker.patch.object(sys, 'argv',
                        ['cekit', '-v', '--config', config, 'generate'])

    with Chdir(str(tmpdir)):
        with open('image.yaml', 'w') as fd:
            yaml.dump(my_image_descriptor, fd, default_flow_style=False)
        c = Cekit().parse()
        c.configure()
        try:
            c.run()
        except SystemExit:
            pass
        with open("target/image/help.md", "r") as fd:
            contents = fd.read()
            assert contents == "2"
예제 #9
0
def test_no_override_help_template(mocker, workdir, tmpdir):
    cleanup(workdir)
    config = setup_config(tmpdir, "")
    mocker.patch.object(sys, 'argv',
                        ['cekit', '-v', '--config', config, 'generate'])
    with Chdir(workdir):
        c = Cekit().parse()
        c.configure()
        try:
            c.run()
        except SystemExit:
            pass
        with open("target/image/help.md", "r") as fd:
            contents = fd.read()
            assert -1 == contents.find(template_teststr)
예제 #10
0
def run_cekit_return_dockerfile(mocker, workdir, argv, getservbyport=getservbyport_works):
    """utility function to invoke cekit and return the generated Dockerfile"""
    mocker.patch.object(sys, 'argv', argv)
    mocker.patch.object(socket, 'getservbyport', getservbyport)
    with Chdir(str(workdir)):
        if os.path.exists('target'):
            shutil.rmtree('target')
        c = Cekit().parse()
        c.configure()
        try:
            c.run()
        except SystemExit:
            pass
        with open("target/image/Dockerfile", "r") as fd:
            return fd.read()
예제 #11
0
def test_config_override_help_template(mocker, workdir, tmpdir):
    cleanup(workdir)
    help_template = os.path.join(workdir, "help.jinja")
    with open(help_template, "w") as fd:
        fd.write(template_teststr)
    config = setup_config(tmpdir,
                          "[doc]\nhelp_template = {}".format(help_template))

    mocker.patch.object(sys, 'argv',
                        ['cekit', '-v', '--config', config, 'generate'])
    with Chdir(workdir):
        c = Cekit().parse()
        c.configure()
        try:
            c.run()
        except SystemExit:
            pass
        with open("target/image/help.md", "r") as fd:
            contents = fd.read()
            assert contents.find(template_teststr) >= 0
예제 #12
0
def test_args_build_pull(mocker):
    mocker.patch.object(sys, 'argv', ['cekit', 'build', '--build-pull'])

    assert Cekit().parse().args.build_pull
예제 #13
0
def run_cekit(cwd):
    with Chdir(cwd):
        c = Cekit().parse()
        c.configure()
        return c.generator._params['addhelp']
예제 #14
0
def test_args_command(mocker, command):
    mocker.patch.object(sys, 'argv', ['cekit', command])

    assert Cekit().parse().args.commands == [command]
예제 #15
0
def test_args_config_default(mocker):
    mocker.patch.object(sys, 'argv', ['cekit',
                                      'generate'])

    assert Cekit().parse().args.config == '~/.cekit/config'
예제 #16
0
def test_args_invalid_build_engine(mocker):
    mocker.patch.object(sys, 'argv', ['cekit', 'build', '--build-engine', 'rkt'])

    with pytest.raises(SystemExit):
        Cekit().parse()
예제 #17
0
def test_args_osbs_stage_false(mocker):
    mocker.patch.object(sys, 'argv', ['cekit', 'build'])

    assert Cekit().parse().args.build_osbs_stage is False
예제 #18
0
def test_args_tags(mocker, tags, build_tags, expected):
    tags = sum([['--tag', t] for t in tags], [])
    build_tags = sum([['--build-tag', t] for t in build_tags], [])

    mocker.patch.object(sys, 'argv', ['cekit', 'generate'] + tags + build_tags)
    assert Cekit().parse().args.tags == expected
예제 #19
0
def test_args_not_valid_command(mocker):
    mocker.patch.object(sys, 'argv', ['cekit', 'explode'])

    with pytest.raises(SystemExit):
        Cekit().parse()
예제 #20
0
def test_args_redhat(mocker):
    mocker.patch.object(sys, 'argv', ['cekit',
                                      '--redhat',
                                      'build'])

    assert Cekit().parse().args.redhat
예제 #21
0
def test_args_build_engine(mocker, engine):
    mocker.patch.object(sys, 'argv', ['cekit', 'build', '--build-engine', engine])

    assert Cekit().parse().args.build_engine == engine
예제 #22
0
def run_cekit_exception(cwd):
    with Chdir(cwd):
        # run cekit and check it exits with 0
        with pytest.raises(SystemExit) as system_exit:
            Cekit().parse().run()
        assert system_exit.value.code == 1
예제 #23
0
def test_args_osbs_stage(mocker):
    mocker.patch.object(sys, 'argv', ['cekit', 'build', '--build-osbs-stage'])

    assert Cekit().parse().args.build_osbs_stage is True