From 3b3312ad662c10aee23be6c90290562c07589a13 Mon Sep 17 00:00:00 2001 From: Guilherme Caulada Date: Mon, 28 Aug 2023 17:22:12 -0300 Subject: [PATCH] Add tests for docker publish manifests functions --- pipelines/docker_publish.go | 6 ++-- pipelines/docker_publish_test.go | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 pipelines/docker_publish_test.go diff --git a/pipelines/docker_publish.go b/pipelines/docker_publish.go index 50d6cad4..6bdb81f1 100644 --- a/pipelines/docker_publish.go +++ b/pipelines/docker_publish.go @@ -18,9 +18,9 @@ func ImageManifest(tag string) string { return manifest[:lastDash] } -func LatestManifest(tag string, base BaseImage) string { +func LatestManifest(tag string) string { suffix := "" - if base == BaseImageUbuntu { + if strings.Contains(tag, "ubuntu") { suffix = "-ubuntu" } @@ -60,7 +60,7 @@ func PublishDocker(ctx context.Context, d *dagger.Client, args PipelineArgs) err manifestTags[manifest] = append(manifestTags[manifest], tag) if opts.Latest { - manifest := LatestManifest(tag, base) + manifest := LatestManifest(tag) manifestTags[manifest] = append(manifestTags[manifest], tag) } diff --git a/pipelines/docker_publish_test.go b/pipelines/docker_publish_test.go new file mode 100644 index 00000000..4e356515 --- /dev/null +++ b/pipelines/docker_publish_test.go @@ -0,0 +1,53 @@ +package pipelines_test + +import ( + "testing" + + "github.com/grafana/grafana-build/pipelines" +) + +func TestImageManifest(t *testing.T) { + manifests := map[string]string{ + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-amd64": "docker.io/grafana/grafana:1.2.3-test.1.2.3", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-amd64": "docker.io/grafana/grafana-oss:1.2.3-test.1.2.3", + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-arm64": "docker.io/grafana/grafana:1.2.3-test.1.2.3", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-arm64": "docker.io/grafana/grafana-oss:1.2.3-test.1.2.3", + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-ubuntu-amd64": "docker.io/grafana/grafana:1.2.3-test.1.2.3-ubuntu", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-ubuntu-amd64": "docker.io/grafana/grafana-oss:1.2.3-test.1.2.3-ubuntu", + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-ubuntu-arm64": "docker.io/grafana/grafana:1.2.3-test.1.2.3-ubuntu", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-ubuntu-arm64": "docker.io/grafana/grafana-oss:1.2.3-test.1.2.3-ubuntu", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-amd64": "docker.io/grafana/grafana-enterprise:1.2.3-test.1.2.3", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-arm64": "docker.io/grafana/grafana-enterprise:1.2.3-test.1.2.3", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-ubuntu-amd64": "docker.io/grafana/grafana-enterprise:1.2.3-test.1.2.3-ubuntu", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-ubuntu-arm64": "docker.io/grafana/grafana-enterprise:1.2.3-test.1.2.3-ubuntu", + } + + for k, v := range manifests { + if n := pipelines.ImageManifest(k); n != v { + t.Errorf("Expected '%s' manifest to equal '%s' but got '%s'", k, v, n) + } + } +} + +func TestLatestManifest(t *testing.T) { + manifests := map[string]string{ + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-amd64": "docker.io/grafana/grafana:latest", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-amd64": "docker.io/grafana/grafana-oss:latest", + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-arm64": "docker.io/grafana/grafana:latest", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-arm64": "docker.io/grafana/grafana-oss:latest", + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-ubuntu-amd64": "docker.io/grafana/grafana:latest-ubuntu", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-ubuntu-amd64": "docker.io/grafana/grafana-oss:latest-ubuntu", + "docker.io/grafana/grafana-image-tags:1.2.3-test.1.2.3-ubuntu-arm64": "docker.io/grafana/grafana:latest-ubuntu", + "docker.io/grafana/grafana-oss-image-tags:1.2.3-test.1.2.3-ubuntu-arm64": "docker.io/grafana/grafana-oss:latest-ubuntu", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-amd64": "docker.io/grafana/grafana-enterprise:latest", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-arm64": "docker.io/grafana/grafana-enterprise:latest", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-ubuntu-amd64": "docker.io/grafana/grafana-enterprise:latest-ubuntu", + "docker.io/grafana/grafana-enterprise-image-tags:1.2.3-test.1.2.3-ubuntu-arm64": "docker.io/grafana/grafana-enterprise:latest-ubuntu", + } + + for k, v := range manifests { + if n := pipelines.LatestManifest(k); n != v { + t.Errorf("Expected '%s' manifest to equal '%s' but got '%s'", k, v, n) + } + } +}