def test_parse_no_env_vars(self): """ Test that if no env variables is specefied none should be loaded """ c = Core({}) c.parse_env_vars() assert c.config.get_tree().get("env", {}) == {}
def test_parse_env_vars(self): """ Test setting env variables from cli and ensure they are set correctly in configuration. """ c = Core({"--env": [ "foo=bar", "opa=1", "barfoo=True", ]}) c.parse_env_vars() assert c.config.get("foo") == "bar" assert c.config.get("opa") == "1" assert c.config.get("barfoo") == "True"
def test_parse_env_vars(self): """ Test setting env variables from cli and ensure they are set correctly in configuration. """ c = Core({ "--env": [ "foo=bar", "opa=1", "barfoo=True", ] }) c.parse_env_vars() assert c.config.get("foo") == "bar" assert c.config.get("opa") == "1" assert c.config.get("barfoo") == "True"
def test_process_dockerfile(self, tmpdir): """ """ input = tmpdir.join("Dockerfile.jinja") input.write("{{ barfoo }}") o = tmpdir.join("Dockerfile") c = tmpdir.join("conf.json") c.write('{"env": {"barfoo": "foobar"}}') c = Core({ "--dockerfile": str(input), "--outfile": str(o), "--config": str(c), }) c.load_user_specefied_config_file() c.parse_env_vars() c.handle_data_sources() c.process_dockerfile() assert o.read() == "foobar"
def test_parse_env_vars_invalid_key(self): """ Test that invalid keyformats cause exceptions """ # specify a key that do not follow the key=value structures c = Core({"--env": ["foo:bar"]}) with pytest.raises(Exception) as ex: c.parse_env_vars() # TODO: str() maybe not py2 & 3 compatible. Look into unicode in from redis._compat assert str( ex.value).startswith("var 'foo:bar' is not of format 'key=value'") c = Core({"--env": ["foo="]}) with pytest.raises(Exception) as ex: c.parse_env_vars() # TODO: str() maybe not py2 & 3 compatible. Look into unicode in from redis._compat assert str( ex.value).startswith("var 'foo=' is not of format 'key=value'") c = Core({"--env": ["=bar"]}) with pytest.raises(Exception) as ex: c.parse_env_vars() # TODO: str() maybe not py2 & 3 compatible. Look into unicode in from redis._compat assert str( ex.value).startswith("var '=bar' is not of format 'key=value'")
def test_parse_env_vars_invalid_key(self): """ Test that invalid keyformats cause exceptions """ # specify a key that do not follow the key=value structures c = Core({ "--env": [ "foo:bar" ] }) with pytest.raises(Exception) as ex: c.parse_env_vars() # TODO: str() maybe not py2 & 3 compatible. Look into unicode in from redis._compat assert str(ex.value).startswith("var 'foo:bar' is not of format 'key=value'") c = Core({ "--env": [ "foo=" ] }) with pytest.raises(Exception) as ex: c.parse_env_vars() # TODO: str() maybe not py2 & 3 compatible. Look into unicode in from redis._compat assert str(ex.value).startswith("var 'foo=' is not of format 'key=value'") c = Core({ "--env": [ "=bar" ] }) with pytest.raises(Exception) as ex: c.parse_env_vars() # TODO: str() maybe not py2 & 3 compatible. Look into unicode in from redis._compat assert str(ex.value).startswith("var '=bar' is not of format 'key=value'")
def test_process_dockerfile_no_output_file_specefied(self, tmpdir): """ Found a bug that if no --outfile is specefied it will not work and throw exception that it should not do... """ input = tmpdir.join("Dockerfile.jinja") input.write("{{ barfoo }}") c = tmpdir.join("conf.json") c.write('{"env": {"barfoo": "foobar"}}') c = Core({ "--dockerfile": str(input), "--config": str(c), }) with pytest.raises(Exception) as ex: c.load_user_specefied_config_file() c.parse_env_vars() c.handle_data_sources() c.process_dockerfile() assert str(ex.value).startswith("missing key '--outfile' in cli_args. Could not write to output file.")
def test_process_dockerfile_no_output_file_specefied(self, tmpdir): """ Found a bug that if no --outfile is specefied it will not work and throw exception that it should not do... """ input = tmpdir.join("Dockerfile.jinja") input.write("{{ barfoo }}") c = tmpdir.join("conf.json") c.write('{"env": {"barfoo": "foobar"}}') c = Core({ "--dockerfile": str(input), "--config": str(c), }) with pytest.raises(Exception) as ex: c.load_user_specefied_config_file() c.parse_env_vars() c.handle_data_sources() c.process_dockerfile() assert str(ex.value).startswith( "missing key '--outfile' in cli_args. Could not write to output file." )