From 5e4893234dee65b159a699d40f127fe23ea91660 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 8 Aug 2024 10:31:38 -0300 Subject: [PATCH] test: fix ko tests the chainguard static image (used in tests) now have a bunch of labels. this adds them to the tests. --- internal/pipe/ko/ko_test.go | 59 +++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/internal/pipe/ko/ko_test.go b/internal/pipe/ko/ko_test.go index 2fa475fa9..6cce4ef53 100644 --- a/internal/pipe/ko/ko_test.go +++ b/internal/pipe/ko/ko_test.go @@ -125,6 +125,12 @@ func TestPublishPipeNoMatchingBuild(t *testing.T) { func TestPublishPipeSuccess(t *testing.T) { testlib.StartRegistry(t, "ko_registry", registryPort) + chainguardStaticLabels := map[string]string{ + "org.opencontainers.image.authors": "Chainguard Team https://www.chainguard.dev/", + "org.opencontainers.image.source": "https://github.com/chainguard-images/images/tree/main/images/static", + "org.opencontainers.image.url": "https://edu.chainguard.dev/chainguard/chainguard-images/reference/static/", + } + table := []struct { Name string SBOM string @@ -138,41 +144,51 @@ func TestPublishPipeSuccess(t *testing.T) { }{ { // Must be first as others add an SBOM for the same image - Name: "sbom-none", - SBOM: "none", + Name: "sbom-none", + SBOM: "none", + ExpectedLabels: chainguardStaticLabels, }, { - Name: "sbom-spdx", - SBOM: "spdx", + Name: "sbom-spdx", + SBOM: "spdx", + ExpectedLabels: chainguardStaticLabels, }, { - Name: "sbom-cyclonedx", - SBOM: "cyclonedx", + Name: "sbom-cyclonedx", + SBOM: "cyclonedx", + ExpectedLabels: chainguardStaticLabels, }, { - Name: "sbom-go.version-m", - SBOM: "go.version-m", + Name: "sbom-go.version-m", + SBOM: "go.version-m", + ExpectedLabels: chainguardStaticLabels, }, { Name: "base-image-is-not-index", BaseImage: "alpine:latest@sha256:c0d488a800e4127c334ad20d61d7bc21b4097540327217dfab52262adc02380c", }, { - Name: "multiple-platforms", - Platforms: []string{"linux/amd64", "linux/arm64"}, + Name: "multiple-platforms", + Platforms: []string{"linux/amd64", "linux/arm64"}, + ExpectedLabels: chainguardStaticLabels, }, { - Name: "labels", - Labels: map[string]string{"foo": "bar", "project": "{{.ProjectName}}"}, - ExpectedLabels: map[string]string{"foo": "bar", "project": "test"}, + Name: "labels", + Labels: map[string]string{"foo": "bar", "project": "{{.ProjectName}}"}, + ExpectedLabels: mapsMerge( + map[string]string{"foo": "bar", "project": "test"}, + chainguardStaticLabels, + ), }, { - Name: "creation-time", - CreationTime: "1672531200", + Name: "creation-time", + CreationTime: "1672531200", + ExpectedLabels: chainguardStaticLabels, }, { Name: "kodata-creation-time", KoDataCreationTime: "1672531200", + ExpectedLabels: chainguardStaticLabels, }, { Name: "tag-templates", @@ -180,6 +196,7 @@ func TestPublishPipeSuccess(t *testing.T) { "{{if not .Prerelease }}{{.Version}}{{ end }}", " ", // empty }, + ExpectedLabels: chainguardStaticLabels, }, { Name: "tag-template-eval-empty", @@ -187,6 +204,7 @@ func TestPublishPipeSuccess(t *testing.T) { "{{.Version}}", "{{if .Prerelease }}latest{{ end }}", }, + ExpectedLabels: chainguardStaticLabels, }, } @@ -523,3 +541,14 @@ func TestApplyTemplate(t *testing.T) { require.Error(t, err) }) } + +func mapsMerge(m1, m2 map[string]string) map[string]string { + result := map[string]string{} + for k, v := range m1 { + result[k] = v + } + for k, v := range m2 { + result[k] = v + } + return result +}