Esempio n. 1
0
 def test_run_in_interactive_mode(self):
     key, value = list(EXAMPLE_VARIABLES.items())[0]
     return_code, stdout, stderr = run_wrapped(
         ["run", "--rm", "-t", "alpine", "printenv", key],
         EXAMPLE_VARIABLES,
         interactive=True)
     self.assertEqual(0, return_code)
Esempio n. 2
0
 def test_run_has_secret_variable(self):
     key, value = list(EXAMPLE_VARIABLES.items())[0]
     return_code, stdout, stderr = run_wrapped(
         ["--debug", "run", "--rm", "alpine", "printenv", key],
         EXAMPLE_VARIABLES)
     self.assertEqual(0, return_code)
     self.assertEqual(value, stdout.strip())
Esempio n. 3
0
 def test_has_standard_variable(self):
     return_code, stdout, stderr = run_wrapped([
         "run", "-e", f"{EXAMPLE_PARAMETER}={EXAMPLE_VALUE}", "--rm",
         "alpine", "printenv", EXAMPLE_PARAMETER
     ], EXAMPLE_VARIABLES)
     self.assertEqual(0, return_code)
     self.assertEqual(EXAMPLE_VALUE, stdout.strip())
Esempio n. 4
0
 def test_run_cli_variable_has_higher_precedence(self):
     other_value = "other-value"
     key, value = list(EXAMPLE_VARIABLES.items())[0]
     return_code, stdout, stderr = run_wrapped([
         "run", "-e", f"{key}={other_value}", "--rm", "alpine", "printenv",
         key
     ], EXAMPLE_VARIABLES)
     self.assertEqual(0, return_code)
     self.assertEqual(other_value, stdout.strip())
Esempio n. 5
0
    def test_run_with_env_file(self):
        key, value = list(EXAMPLE_VARIABLES.items())[0]
        key_2, value_2 = list(EXAMPLE_VARIABLES.items())[2]
        example_override = "override"

        with NamedTemporaryFile("w") as env_file:
            env_file.write(f"{key}={example_override}")
            env_file.flush()
            return_code, stdout, stderr = run_wrapped([
                "run", "--env-file", f"{env_file.name}", "--rm", "alpine",
                "printenv", key
            ], EXAMPLE_VARIABLES)
            self.assertEqual(0, return_code)
            self.assertEqual(example_override, stdout.strip())

            return_code, stdout, stderr = run_wrapped([
                "run", "--env-file", f"{env_file.name}", "--rm", "alpine",
                "printenv", key_2
            ], EXAMPLE_VARIABLES)
            self.assertEqual(0, return_code)
            self.assertEqual(value_2, stdout.strip())
def run(cli_configuration: CliConfiguration) -> ProgramOutputType:
    """
    Runs the program according to the given run configuration. 
    :param cli_configuration: the run configuration
    :return: the run output
    """
    configuration = parse_configuration(
        cli_configuration.config_location if cli_configuration.
        config_location is not None else DEFAULT_CONFIG_FILE)

    project = cli_configuration.project if cli_configuration.project is not None else configuration.gitlab.project
    if _NAMESPACE_PROJECT_SEPARATOR not in project:
        project = f"{configuration.gitlab.namespace}{_NAMESPACE_PROJECT_SEPARATOR}{project}"

    gitlab_config = GitLabConfig(configuration.gitlab.url,
                                 configuration.gitlab.token)
    project_variables_manager = ProjectVariablesManager(gitlab_config, project)
    project_variables = project_variables_manager.get()

    return run_wrapped(cli_configuration.docker_args, project_variables,
                       cli_configuration.interactive)
Esempio n. 7
0
 def test_run_has_multiline_secret_variable(self):
     key, value = list(EXAMPLE_VARIABLES.items())[1]
     return_code, stdout, stderr = run_wrapped(
         ["run", "--rm", "alpine", "printenv", key], EXAMPLE_VARIABLES)
     self.assertEqual(0, return_code)
     self.assertEqual(value.replace("\n", SAFE_LINE_BREAK), stdout.strip())
Esempio n. 8
0
 def test_with_non_supported_action(self):
     return_code, stdout, stderr = run_wrapped(["version"],
                                               EXAMPLE_VARIABLES)
     self.assertEqual(0, return_code)
     self.assertIn("Version", stdout.strip())
Esempio n. 9
0
 def test_help_with_docker_command(self):
     return_code, stdout, stderr = run_wrapped(["ps", "--help"],
                                               EXAMPLE_VARIABLES)
     self.assertEqual(0, return_code)
     self.assertIn("Usage:\tdocker ps", stdout.strip())