def test_component_should_run() -> None: """Test whether components should be executed.""" c1 = Component(RunRecipe(), [ImageName("ubuntu"), ImageName("debian", "stretch")]) c2 = Component(BuildRecipe(["FROM nixos"])) i1 = ImageName("ubuntu") i2 = ImageName("ubuntu", "18.04") i3 = ImageName("debian") i4 = ImageName("debian", "stretch") i5 = ImageName("debian", "jessie") i6 = ImageName("arch") assert c1.should_run(i1) assert c1.should_run(i2) assert not c1.should_run(i3) assert c1.should_run(i4) assert not c1.should_run(i5) assert not c1.should_run(i6) assert c2.should_run(i1) assert c2.should_run(i2) assert c2.should_run(i3) assert c2.should_run(i4) assert c2.should_run(i5) assert c2.should_run(i6)
def test_component_initialisation() -> None: """Test creating components.""" Component(BuildRecipe(["RUN cd ."])) Component( RunRecipe(script=["a", "b"]), [ImageName.from_str("a/b:c"), ImageName("qwerty", "uiop")], None, "does absolutely nothing", )
def test_module_load_valid() -> None: """Test loading a module from a file.""" with open(MODULE_VALID) as fp: assert Module.load_from_file(fp) == Module( name="example module", description="A module which is also an example!", components=[ Component( BuildRecipe( commands=["FROM example-image", "RUN some-setup-cmd"], )), Component( RunRecipe(script=["./fix-bug.sh --version 19.07"]), compatible=[ImageName("example-image", "19.07")], ), ], )
def test_component_load_valid() -> None: """Test loading a component from a file.""" with open(COMPONENT_VALID) as fp: assert Component.load_from_file(fp) == Component( recipe=BuildRecipe(commands=["RUN cd .."]), compatible=[ImageName("example"), ImageName("test", "13.2")], description="A very exciting component.", )
def test_environmentdefinition_load_valid() -> None: """Test loading Environment Definition from file.""" m1 = Module( name="ubuntu", components=[ Component( recipe=BuildRecipe(commands=["FROM ubuntu"]), results=ImageName("ubuntu"), ) ], ) m2 = Module( name="zsh", components=[ Component( recipe=BuildRecipe( commands=["RUN apt update && apt install zsh"]), compatible=[ImageName("ubuntu"), ImageName("debian")], description="Installs zsh using apt.", ), Component( recipe=BuildRecipe(commands=["RUN pacman -S zsh"]), compatible=[ImageName("arch"), ImageName("manjaro")], description="Installs zsh using pacman.", ), Component( recipe=BuildRecipe(commands=["CMD zsh"]), description="Use zsh as the entry command.", ), Component(recipe=RunRecipe(ports=[(3000, 3000), (8080, 8080)]), ) ], ) env_valid = EnvironmentDefinition( name="example-environment", modules=[m1, m2], ) with open(ENV_VALID) as fp: assert EnvironmentDefinition.load_from_file(fp) == env_valid
def test_module_instantiation() -> None: """Test creating modules.""" Module("example", [Component(RunRecipe())]) Module("banana", [], "adds random bananas to your shell")