Exemple #1
0
    def test_project_2_fallback(self, project_loader):
        project_loader("project2")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(SymlinksFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.islink('test')
        assert os.readlink('test') == 'test.stage'
        assert os.path.exists('test')

        assert os.path.islink('test.yml')
        assert os.readlink('test.yml') == 'test.dev.yml'
        assert os.path.exists('test.yml')

        assert os.path.islink('test2')
        assert os.readlink('test2') == 'test2.prod'
        assert os.path.exists('test2')

        assert not os.path.islink('test3')
Exemple #2
0
    def test_autofix_eol(self, project_loader):
        project_loader("autofix_eol")

        history = (
            PropertyMigration("docker.compose.network_name",
                              "jsonnet.docker.compose.network_name",
                              since="v1.6.0"),
            PropertyMigration("docker.port_prefix",
                              "jsonnet.docker.expose.port_prefix",
                              since="v1.6.0"),
        )

        migrations.set_history(history)

        features.register(FileFeature())
        features.register(JinjaFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        with open('docker-compose.properties', 'r') as f:
            rendered = f.read()

        with open('docker-compose.expected.properties', 'r') as f:
            expected = f.read()

        assert rendered == expected
Exemple #3
0
    def test_example1_yaml(self, project_loader):
        project_loader("example1.yaml")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('example1.another')
        with open('example1.another', 'r') as f:
            example_another = f.read()

        with open('example1.expected.another', 'r') as f:
            example_another_expected = f.read()

        assert example_another == example_another_expected

        assert os.path.exists('example1.yaml')
        with open('example1.yaml', 'r') as f:
            example_yaml = f.read()

        with open('example1.expected.yaml', 'r') as f:
            example_yaml_expected = f.read()

        assert example_yaml == example_yaml_expected
Exemple #4
0
    def test_empty_project_without_core(self, project_loader):
        project_loader("empty")

        features.register(FileFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()
Exemple #5
0
    def test_empty_configuration_with_core(self, project_loader):
        project_loader("empty")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(SymlinksFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()
Exemple #6
0
    def test_ignore_invalid_extension(self, project_loader):
        project_loader("ignore_invalid_extension")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(YttFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert not os.path.exists('yaml.txt')
        assert not os.path.exists('yaml.yml')
Exemple #7
0
    def test_project_many_prod(self, project_loader):
        project_loader("project_many_prod")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(SymlinksFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.islink('test.yml')
        assert os.readlink('test.yml') == 'test.prod.yml'
Exemple #8
0
    def test_inherit_from_template(self, project_loader):
        project_loader("inherit_from_template")
        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JinjaFeature())
        features.register(PermissionsFeature())

        load_registered_features()
        register_actions_in_event_bus()

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists("script.sh")
        assert os.access("script.sh", os.X_OK)
Exemple #9
0
    def test_project2(self, project_loader):
        project_loader("project2")
        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(PermissionsFeature())

        load_registered_features()
        register_actions_in_event_bus()

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.access("script.sh", os.X_OK)
        assert os.access(os.path.join("subdirectory", "another-script.sh"),
                         os.X_OK)
Exemple #10
0
    def test_docker_compose_variants(self, project_loader, variant):
        project_loader("docker_compose" + variant)

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(DockerFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('docker-compose.yml')
        with open('docker-compose.yml', 'r') as f:
            rendered = yaml.load(f.read(), yaml.SafeLoader)

        with open('docker-compose.expected.yml', 'r') as f:
            expected_data = f.read()

            if os.name == 'nt':
                mapped_cwd = re.sub(r"^([a-zA-Z]):", r"/\1", os.getcwd())
                mapped_cwd = pathlib.Path(mapped_cwd).as_posix()

                expected_data = expected_data.replace("%ddb.path.project%",
                                                      mapped_cwd)
            else:
                expected_data = expected_data.replace("%ddb.path.project%",
                                                      os.getcwd())
            expected_data = expected_data.replace(
                "%uid%", str(config.data.get('docker.user.uid')))
            expected_data = expected_data.replace(
                "%gid%", str(config.data.get('docker.user.gid')))
            expected_data = expected_data.replace(
                "%docker.debug.host%",
                str(config.data.get('docker.debug.host')))

            expected = yaml.load(expected_data, yaml.SafeLoader)

        assert rendered == expected

        if variant == '_mount_single_volume':
            assert os.path.isdir('volumes/shared-volume')

        if variant == '_mount_single_volume_with_default':
            assert os.path.isdir('shared-volume')
Exemple #11
0
    def test_docker_compose_traefik_defaults(self, project_loader, variant):
        def before_load_config():
            os.rename("ddb.%s.yml" % variant, "ddb.yml")
            os.rename("docker-compose.expected.%s.yml" % variant,
                      "docker-compose.expected.yml")

        project_loader("docker_compose_traefik_defaults", before_load_config)

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(DockerFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('docker-compose.yml')
        with open('docker-compose.yml', 'r') as f:
            rendered = yaml.load(f.read(), yaml.SafeLoader)

        with open('docker-compose.expected.yml', 'r') as f:
            expected_data = f.read()

            if os.name == 'nt':
                mapped_cwd = re.sub(r"^([a-zA-Z]):", r"/\1", os.getcwd())
                mapped_cwd = pathlib.Path(mapped_cwd).as_posix()

                expected_data = expected_data.replace("%ddb.path.project%",
                                                      mapped_cwd)
            else:
                expected_data = expected_data.replace("%ddb.path.project%",
                                                      os.getcwd())
            expected_data = expected_data.replace(
                "%uid%", str(config.data.get('docker.user.uid')))
            expected_data = expected_data.replace(
                "%gid%", str(config.data.get('docker.user.gid')))
            expected_data = expected_data.replace(
                "%docker.debug.host%",
                str(config.data.get('docker.debug.host')))

            expected = yaml.load(expected_data, yaml.SafeLoader)

        assert rendered == expected
Exemple #12
0
    def test_project4(self, project_loader):
        project_loader("project4")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JinjaFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('foo')
        with open('foo', 'r') as f:
            foo = f.read()

        assert foo == 'env=dev'
Exemple #13
0
    def test_project_keep_trailing_lines_default(self, project_loader):
        project_loader("trailing-newline")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JinjaFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('foo.yml')
        with open('foo.yml', 'r') as f:
            foo = f.read()

        assert foo == 'test: trailing\n'
Exemple #14
0
    def test_project_4_subdirectory(self, project_loader):
        project_loader("project4")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(SymlinksFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.islink(os.path.join('subdirectory', 'test.yml'))
        assert os.readlink(os.path.join('subdirectory',
                                        'test.yml')) == 'test.dev.yml'

        assert os.path.exists(os.path.join('subdirectory', 'test.yml'))

        assert not os.path.islink('no.yml')
Exemple #15
0
    def test_autofix_variables_only(self, project_loader):
        project_loader("autofix_variables_only")

        config.args.autofix = True

        history = (
            PropertyMigration("old_property", "new_property", since="v1.1.0"),
            PropertyMigration("some.deep.old.property",
                              "some.another.new.property",
                              since="v1.1.0"),
        )

        migrations.set_history(history)

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(DockerFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('variables.json')
        with open('variables.json', 'r') as f:
            rendered = f.read()

        with open('variables.expected.json', 'r') as f:
            expected = f.read()

        assert expected == rendered

        with open('variables.json.jsonnet', 'r') as f:
            source = f.read()

        with open('variables.json.autofix', 'r') as f:
            fixed = f.read()

        assert source == fixed
Exemple #16
0
    def test_project2(self, project_loader):
        project_loader("project2")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JinjaFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('foo.yml')
        with open('foo.yml', 'r') as f:
            foo = f.read()

        assert foo == 'env: dev\nincluded: True'

        assert not os.path.exists(os.path.join("partial", "_partial.yml"))
        assert not os.path.exists(os.path.join("partial", "partial.yml"))
Exemple #17
0
    def test_config_variables(self, project_loader):
        project_loader("config_variables")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('variables.json')
        with open('variables.json', 'r') as f:
            variables = f.read()

        with open('variables.expected.json', 'r') as f:
            variables_expected = f.read()

        assert variables == variables_expected
Exemple #18
0
    def test_example2(self, project_loader):
        project_loader("example2")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('example2.json')
        with open('example2.json', 'r') as f:
            example = f.read()

        with open('example2.expected.json', 'r') as f:
            example_expected = f.read()

        assert example == example_expected
Exemple #19
0
    def test_depends_suffixes(self, project_loader):
        project_loader("depends_suffixes")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(YttFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('variables.yaml')
        with open('variables.yaml', 'r') as f:
            rendered = f.read()

        with open('variables.expected.yaml', 'r') as f:
            expected = f.read()

        assert rendered == expected
Exemple #20
0
    def test_autofix_eol2(self, project_loader):
        project_loader("autofix_eol2")

        config.args.autofix = True

        history = (
            PropertyMigration("docker.compose.network_name",
                              "jsonnet.docker.compose.network_name",
                              since="v1.6.0"),
            PropertyMigration("docker.port_prefix",
                              "jsonnet.docker.expose.port_prefix",
                              since="v1.6.0"),
        )

        migrations.set_history(history)

        features.register(FileFeature())
        features.register(JinjaFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        with open('msmtprc', 'r') as f:
            rendered = f.read()

        with open('msmtprc.expected', 'r') as f:
            expected = f.read()

        assert rendered == expected

        with open('msmtprc.jinja', 'r') as f:
            template = f.read()

        with open('msmtprc.autofix', 'r') as f:
            autofix = f.read()

        assert autofix == template
Exemple #21
0
    def test_example3_with_dir(self, project_loader):
        project_loader("example3.with_dir")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('./target/uwsgi.ini')
        with open('./target/uwsgi.ini', 'r') as f:
            iwsgi = f.read()

        with open('uwsgi.expected.ini', 'r') as f:
            iwsgi_expected = f.read()

        assert iwsgi == iwsgi_expected

        assert os.path.exists('./target/init.sh')
        with open('./target/init.sh', 'r') as f:
            init = f.read()

        with open('init.expected.sh', 'r') as f:
            init_expected = f.read()

        assert init == init_expected

        assert os.path.exists('./target/cassandra.conf')
        with open('./target/cassandra.conf', 'r') as f:
            cassandra = f.read()

        with open('cassandra.expected.conf', 'r') as f:
            cassandra_expected = f.read()

        assert cassandra == cassandra_expected
Exemple #22
0
    def test_docker_compose_xdebug(self, project_loader, variant):
        def before_load_config():
            os.rename("ddb.%s.yml" % variant, "ddb.yml")
            os.rename("docker-compose.expected.%s.yml" % variant,
                      "docker-compose.expected.yml")

        project_loader("docker_compose_xdebug", before_load_config)

        print(os.getcwd())

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(DockerFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('docker-compose.yml')
        with open('docker-compose.yml', 'r') as f:
            rendered = yaml.load(f.read(), yaml.SafeLoader)

        with open('docker-compose.expected.yml', 'r') as f:
            expected_data = f.read()

            expected_data = expected_data.replace(
                "%uid%", str(config.data.get('docker.user.uid')))
            expected_data = expected_data.replace(
                "%gid%", str(config.data.get('docker.user.gid')))
            expected_data = expected_data.replace(
                "%docker.debug.host%",
                str(config.data.get('docker.debug.host')))

            expected = yaml.load(expected_data, yaml.SafeLoader)

        assert rendered == expected
Exemple #23
0
    def test_docker_compose_included_services(self, project_loader):
        project_loader("docker_compose_included_services")

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(DockerFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('docker-compose.yml')
        with open('docker-compose.yml', 'r') as f:
            rendered = yaml.load(f.read(), yaml.SafeLoader)

        with open('docker-compose.expected.yml', 'r') as f:
            expected_data = f.read()
            expected = yaml.load(expected_data, yaml.SafeLoader)

        assert rendered == expected