def test_parent_images_mismatch_base_image(tmpdir): """test when base_image has been updated differently from parent_images.""" dfp = df_parser(str(tmpdir)) dfp.content = "FROM base:image" workflow = mock_workflow() workflow.builder.set_df_path(dfp.dockerfile_path) workflow.builder.base_image = ImageName.parse("base:image") workflow.builder.parent_images = {"base:image": "different-parent-tag"} with pytest.raises(BaseImageMismatch): ChangeFromPlugin(docker_tasker(), workflow).run()
def test_parent_images_unresolved(tmpdir): """test when parent_images hasn't been filled in with unique tags.""" dfp = df_parser(str(tmpdir)) dfp.content = "FROM spam" workflow = mock_workflow() workflow.builder.set_df_path(dfp.dockerfile_path) workflow.builder.base_image = ImageName.parse('eggs') # we want to fail because some img besides base was not resolved workflow.builder.parent_images = {'spam': 'eggs', 'extra:image': None} with pytest.raises(ParentImageUnresolved): ChangeFromPlugin(docker_tasker(), workflow).run()
def test_parent_images_missing(tmpdir, docker_tasker): """test when parent_images has been mangled and lacks parents compared to dockerfile.""" dfp = df_parser(str(tmpdir)) dfp.content = dedent("""\ FROM first:parent AS builder1 FROM second:parent AS builder2 FROM monty """) workflow = mock_workflow() workflow.builder.set_df_path(dfp.dockerfile_path) workflow.builder.parent_images = {ImageName.parse("monty"): ImageName.parse("build-name:3")} workflow.builder.base_image = ImageName.parse("build-name:3") with pytest.raises(ParentImageMissing): ChangeFromPlugin(docker_tasker, workflow).run()
def test_update_base_image_inspect_broken(tmpdir, caplog): """exercise code branch where the base image inspect comes back without an Id""" df_content = "FROM base:image" dfp = df_parser(str(tmpdir)) dfp.content = df_content workflow = mock_workflow() workflow.builder.set_df_path(dfp.dockerfile_path) workflow.builder.parent_images = {"base:image": "base@sha256:1234"} workflow.builder.base_image = ImageName.parse("base@sha256:1234") workflow.builder.tasker.inspect_image = lambda img: dict(no_id="here") with pytest.raises(NoIdInspection): ChangeFromPlugin(docker_tasker(), workflow).run() assert dfp.content == df_content # nothing changed assert "missing in inspection" in caplog.text()