Exemplo n.º 1
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'
Exemplo n.º 2
0
    def test_project3(self, project_loader):
        project_loader("project3")
        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)
        assert os.access(os.path.join("subdirectory"), os.W_OK)
        assert not os.access(os.path.join("denied"), os.W_OK)
Exemplo n.º 3
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')
Exemplo n.º 4
0
    def test_project_1(self, project_loader):
        project_loader("project1")

        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.exists('test')
        assert os.path.islink('test')
        assert os.path.exists('test')

        assert os.path.exists('test.yml')
        assert os.path.islink('test.yml')
        assert os.path.exists('test.yml')
Exemplo n.º 5
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
Exemplo n.º 6
0
    def test_docker_compose_variables(self, project_loader):
        project_loader("docker_compose_variables")

        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
Exemplo n.º 7
0
    def test_example1(self, project_loader):
        project_loader("example1")

        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.json')
        with open('example1.json', 'r') as f:
            example = f.read()

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

        assert example == example_expected
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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"))
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
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
Exemplo n.º 15
0
    def test_project5(self, project_loader):
        project_loader("project5")

        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'

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

        assert foo == 'env: dev'