Exemple #1
0
    def test_run_binary_condition(self, project_loader,
                                  capsys: CaptureFixture):
        project_loader("empty")

        features.register(CoreFeature())
        features.register(RunFeature())
        features.register(ShellFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        binary1 = DockerBinary("npm", "node1")
        binary2 = DockerBinary("npm", "node2")
        default_binary = DefaultBinary("npm", ["npm"])
        binary4 = DockerBinary("npm", "node4")
        binary_invalid_condition = DockerBinary(
            "npm", "node5", condition="'another-value' in args")
        binary_valid_condition = DockerBinary("npm",
                                              "node6",
                                              condition="'some-value' in args")

        for bin in (binary1, binary2, default_binary, binary4,
                    binary_invalid_condition, binary_valid_condition):
            binaries.register(bin)

        action = RunAction()
        action.run("npm", "some-value")

        read = capsys.readouterr()
        assert "node6" in read.out
    def test_docker_binary_compare_ne(self):
        binary1 = DockerBinary("npm", "node1")
        binary2 = DockerBinary("npm", "node2")
        binary3 = DockerBinary("npm", "node3")
        binary4 = DockerBinary("npm", "node4")

        assert binary1 != binary2 != binary3 != binary4
        assert hash(binary1) != hash(binary2) != hash(binary3) != hash(binary4)
Exemple #3
0
    def test_run_docker_binary_exe(self, project_loader,
                                   capsys: CaptureFixture):
        project_loader("exe")

        features.register(CoreFeature())
        features.register(RunFeature())
        features.register(ShellFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        binaries.register(
            DockerBinary("echo",
                         docker_compose_service="web",
                         args="echo",
                         exe=True))

        DockerUtils.service_stop('web')
        assert not DockerUtils.is_container_up('web')

        action = RunAction()
        action.run("echo")

        read = capsys.readouterr()

        assert read.out == docker_compose_bin + " exec web echo\n"

        assert DockerUtils.is_container_up('web')
Exemple #4
0
    def test_run_docker_binary_workdir_outside(self, project_loader,
                                               capsys: CaptureFixture):
        project_loader("outside")
        config.cwd = os.path.join(config.paths.project_home, "../outside")

        features.register(CoreFeature())
        features.register(RunFeature())
        features.register(ShellFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        binaries.register(DockerBinary("bin", "service", "/app"))

        action = RunAction()
        action.run("bin")

        read = capsys.readouterr()

        cwd = config.cwd if config.cwd else os.getcwd()
        real_cwd = os.path.realpath(cwd)

        assert read.out == docker_compose_bin + " -f ../project/docker-compose.yml " \
                                                "run --rm "\
                                                f"--volume={real_cwd}:/app " \
                                                "--workdir=/app " \
                                                "service\n"
    def test_binary_ordering(self):
        binary1 = DockerBinary("npm", "node1")
        binary2 = DockerBinary("npm", "node2")
        default_binary = DefaultBinary("npm", ["npm"])
        binary4 = DockerBinary("npm", "node4")
        binary_with_condition = DockerBinary("npm",
                                             "node5",
                                             condition="some-condition")

        bins = (binary1, binary2, default_binary, binary4,
                binary_with_condition)

        r = RegistryOrderedSet(Binary, "Binary")
        for bin in bins:
            r.register(bin)

        assert r.all() == bins
        npm_binaries = r.get("npm")

        assert npm_binaries == bins
    def test_docker_binary_sort(self):
        binary1 = DockerBinary("npm", "node1")
        binary2 = DockerBinary("npm", "node2")
        binary3 = DefaultBinary("npm", ["npm"])
        binary4 = DockerBinary("npm", "node4")

        bins = (binary1, binary2, binary3, binary4)
        sorted_bins = tuple(sorted(bins))
        expected = (binary1, binary2, binary4, binary3)

        assert sorted_bins == expected

        binary_with_condition = DockerBinary("npm",
                                             "node5",
                                             condition="some-condition")

        bins = (binary1, binary2, binary_with_condition, binary3, binary4)
        sorted_bins = tuple(sorted(bins))
        expected = (binary_with_condition, binary1, binary2, binary4, binary3)

        assert sorted_bins == expected
Exemple #7
0
    def test_run_docker_binary(self, project_loader, capsys: CaptureFixture):
        project_loader("empty")
        config.cwd = config.paths.project_home

        features.register(CoreFeature())
        features.register(RunFeature())
        features.register(ShellFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        binaries.register(DockerBinary("bin", "service", "/app"))

        action = RunAction()
        action.run("bin")

        read = capsys.readouterr()

        assert read.out == docker_compose_bin + " run --rm --workdir=/app/. service\n"
    def test_docker_binary_compare_eq(self):
        binary1 = DockerBinary("npm", "node")
        binary2 = DockerBinary("npm", "node")

        assert binary1 == binary2
        assert hash(binary1) == hash(binary2)