From 1318c6fee6bbc786f2517608e520c457be071072 Mon Sep 17 00:00:00 2001 From: TristanHoladay <40547442+TristanHoladay@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:36:39 -0600 Subject: [PATCH 1/4] chore: ensure vendored tools versions print out --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 87e35fca..b663ca74 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,18 @@ ARCH ?= amd64 CLI_VERSION ?= $(if $(shell git describe --tags),$(shell git describe --tags),"UnknownVersion") +K9S_VERSION=$(shell go list -f '{{.Version}}' -m github.com/derailed/k9s) +CRANE_VERSION=$(shell go list -f '{{.Version}}' -m github.com/google/go-containerregistry) +SYFT_VERSION=$(shell go list -f '{{.Version}}' -m github.com/anchore/syft) +ARCHIVER_VERSION=$(shell go list -f '{{.Version}}' -m github.com/mholt/archiver/v3) +HELM_VERSION=$(shell go list -f '{{.Version}}' -m helm.sh/helm/v3) BUILD_ARGS := -s -w -X 'github.com/defenseunicorns/uds-cli/src/config.CLIVersion=$(CLI_VERSION)' \ - -X 'github.com/defenseunicorns/zarf/src/config.ActionsCommandZarfPrefix=zarf' + -X 'github.com/defenseunicorns/zarf/src/config.ActionsCommandZarfPrefix=zarf' \ + -X 'github.com/derailed/k9s/cmd.version=$(K9S_VERSION)' \ + -X 'github.com/google/go-containerregistry/cmd/crane/cmd.Version=$(CRANE_VERSION)' \ + -X 'github.com/defenseunicorns/zarf/src/cmd/tools.syftVersion=$(SYFT_VERSION)' \ + -X 'github.com/defenseunicorns/zarf/src/cmd/tools.archiverVersion=$(ARCHIVER_VERSION)' \ + -X 'github.com/defenseunicorns/zarf/src/cmd/tools.helmVersion=$(HELM_VERSION)' .PHONY: help help: ## Display this help information From fac4a408a383f18d7ded3d4b8d8619952050c7f9 Mon Sep 17 00:00:00 2001 From: TristanHoladay <40547442+TristanHoladay@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:24:42 -0600 Subject: [PATCH 2/4] added initial tools version test --- src/test/e2e/zarf_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/e2e/zarf_test.go b/src/test/e2e/zarf_test.go index c5807505..67784c9d 100644 --- a/src/test/e2e/zarf_test.go +++ b/src/test/e2e/zarf_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + "github.com/defenseunicorns/zarf/src/pkg/utils/exec" "github.com/stretchr/testify/require" ) @@ -20,3 +21,22 @@ func TestZarfLint(t *testing.T) { require.NoError(t, err) require.Contains(t, stdErr, "Image not pinned with digest - ghcr.io/stefanprodan/podinfo:6.4.0") } + +// K9S_VERSION=$(shell go list -f '{{.Version}}' -m github.com/derailed/k9s) +// CRANE_VERSION=$(shell go list -f '{{.Version}}' -m github.com/google/go-containerregistry) +// SYFT_VERSION=$(shell go list -f '{{.Version}}' -m github.com/anchore/syft) +// ARCHIVER_VERSION=$(shell go list -f '{{.Version}}' -m github.com/mholt/archiver/v3) +// HELM_VERSION=$(shell go list -f '{{.Version}}' -m helm.sh/helm/v3) + +// // vendored tool versions are set as build args +func TestZarfToolsVersions(t *testing.T) { + cmd := strings.Split("zarf tools helm version", " ") + _, stderr, err := e2e.UDS(cmd...) + getHelmVersionCmd := strings.Split("list -f '{{.Version}}' -m helm.sh/helm/v3", " ") + versionRes, _, _ := exec.Cmd("go", getHelmVersionCmd...) + helmVersion := strings.Split(versionRes, "'") + version := strings.Split(stderr, "\n") + require.NoError(t, err) + require.Contains(t, version[4], "helm") + require.Contains(t, version[4], helmVersion[1]) +} From c230700fd315630ebf5e75f7a2d42170c171111f Mon Sep 17 00:00:00 2001 From: TristanHoladay <40547442+TristanHoladay@users.noreply.github.com> Date: Mon, 29 Apr 2024 20:42:52 -0600 Subject: [PATCH 3/4] refactor and add tests --- src/test/e2e/zarf_test.go | 64 +++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/test/e2e/zarf_test.go b/src/test/e2e/zarf_test.go index 67784c9d..43236246 100644 --- a/src/test/e2e/zarf_test.go +++ b/src/test/e2e/zarf_test.go @@ -5,6 +5,7 @@ package test import ( + "fmt" "strings" "testing" @@ -22,21 +23,52 @@ func TestZarfLint(t *testing.T) { require.Contains(t, stdErr, "Image not pinned with digest - ghcr.io/stefanprodan/podinfo:6.4.0") } -// K9S_VERSION=$(shell go list -f '{{.Version}}' -m github.com/derailed/k9s) -// CRANE_VERSION=$(shell go list -f '{{.Version}}' -m github.com/google/go-containerregistry) -// SYFT_VERSION=$(shell go list -f '{{.Version}}' -m github.com/anchore/syft) -// ARCHIVER_VERSION=$(shell go list -f '{{.Version}}' -m github.com/mholt/archiver/v3) -// HELM_VERSION=$(shell go list -f '{{.Version}}' -m helm.sh/helm/v3) - -// // vendored tool versions are set as build args func TestZarfToolsVersions(t *testing.T) { - cmd := strings.Split("zarf tools helm version", " ") - _, stderr, err := e2e.UDS(cmd...) - getHelmVersionCmd := strings.Split("list -f '{{.Version}}' -m helm.sh/helm/v3", " ") - versionRes, _, _ := exec.Cmd("go", getHelmVersionCmd...) - helmVersion := strings.Split(versionRes, "'") - version := strings.Split(stderr, "\n") - require.NoError(t, err) - require.Contains(t, version[4], "helm") - require.Contains(t, version[4], helmVersion[1]) + type args struct { + tool string + toolRepo string + } + tests := []struct { + name string + description string + args args + }{ + { + name: "HelmVersion", + description: "zarf tools helm version", + args: args{tool: "helm", toolRepo: "helm.sh/helm/v3"}, + }, + { + name: "Crane Version", + description: "zarf tools crane version", + args: args{tool: "crane", toolRepo: "github.com/google/go-containerregistry"}, + }, + { + name: "Syft Version", + description: "zarf tools syft version", + args: args{tool: "syft", toolRepo: "github.com/anchore/syft"}, + }, + { + name: "Archiver Version", + description: "zarf tools archiver version", + args: args{tool: "archiver", toolRepo: "github.com/mholt/archiver/v3"}, + }, + } + + for _, tt := range tests { + cmdStr := fmt.Sprintf("zarf tools %s version", tt.args.tool) + res, stdErr, err := e2e.UDS(strings.Split(cmdStr, " ")...) + require.NoError(t, err) + + toolVerRepoStr := fmt.Sprintf("list -f '{{.Version}}' -m %s", tt.args.toolRepo) + verRes, _, verErr := exec.Cmd("go", strings.Split(toolVerRepoStr, " ")...) + require.NoError(t, verErr) + + toolVersion := strings.Split(verRes, "'") + toMatch := res + if res == "" { + toMatch = stdErr + } + require.Contains(t, toMatch, toolVersion[1]) + } } From 2076bcfbb9ebcfe1449129d649fb2d05e4096523 Mon Sep 17 00:00:00 2001 From: TristanHoladay <40547442+TristanHoladay@users.noreply.github.com> Date: Tue, 30 Apr 2024 08:20:02 -0600 Subject: [PATCH 4/4] refactor TestZarfToolsVersion; add comment to DeleteZarfPkg --- src/test/common.go | 3 ++- src/test/e2e/zarf_test.go | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/test/common.go b/src/test/common.go index b9046e5c..d2018597 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -159,7 +159,7 @@ func (e2e *UDSE2ETest) DownloadZarfInitPkg(t *testing.T, zarfVersion string) { require.NoError(t, err) } -// CreateZarfPkg creates a Zarf in the given path (todo: makefile?) +// CreateZarfPkg creates a Zarf package in the given path (todo: makefile?) func (e2e *UDSE2ETest) CreateZarfPkg(t *testing.T, path string, forceCreate bool) { // check if pkg already exists pattern := fmt.Sprintf("%s/*-%s-*.tar.zst", path, e2e.Arch) @@ -174,6 +174,7 @@ func (e2e *UDSE2ETest) CreateZarfPkg(t *testing.T, path string, forceCreate bool require.NoError(t, err) } +// DeleteZarfPkg deletes a Zarf package from the given path func (e2e *UDSE2ETest) DeleteZarfPkg(t *testing.T, path string) { // check if pkg already exists pattern := fmt.Sprintf("%s/*-%s-*.tar.zst", path, e2e.Arch) diff --git a/src/test/e2e/zarf_test.go b/src/test/e2e/zarf_test.go index 43236246..81a687b8 100644 --- a/src/test/e2e/zarf_test.go +++ b/src/test/e2e/zarf_test.go @@ -39,36 +39,36 @@ func TestZarfToolsVersions(t *testing.T) { args: args{tool: "helm", toolRepo: "helm.sh/helm/v3"}, }, { - name: "Crane Version", + name: "CraneVersion", description: "zarf tools crane version", args: args{tool: "crane", toolRepo: "github.com/google/go-containerregistry"}, }, { - name: "Syft Version", + name: "SyftVersion", description: "zarf tools syft version", args: args{tool: "syft", toolRepo: "github.com/anchore/syft"}, }, { - name: "Archiver Version", + name: "ArchiverVersion", description: "zarf tools archiver version", args: args{tool: "archiver", toolRepo: "github.com/mholt/archiver/v3"}, }, } for _, tt := range tests { - cmdStr := fmt.Sprintf("zarf tools %s version", tt.args.tool) - res, stdErr, err := e2e.UDS(strings.Split(cmdStr, " ")...) + cmdArgs := fmt.Sprintf("zarf tools %s version", tt.args.tool) + res, stdErr, err := e2e.UDS(strings.Split(cmdArgs, " ")...) require.NoError(t, err) - toolVerRepoStr := fmt.Sprintf("list -f '{{.Version}}' -m %s", tt.args.toolRepo) - verRes, _, verErr := exec.Cmd("go", strings.Split(toolVerRepoStr, " ")...) + toolRepoVerArgs := fmt.Sprintf("list -f '{{.Version}}' -m %s", tt.args.toolRepo) + verRes, _, verErr := exec.Cmd("go", strings.Split(toolRepoVerArgs, " ")...) require.NoError(t, verErr) - toolVersion := strings.Split(verRes, "'") - toMatch := res + toolVersion := strings.Split(verRes, "'")[1] + output := res if res == "" { - toMatch = stdErr + output = stdErr } - require.Contains(t, toMatch, toolVersion[1]) + require.Contains(t, output, toolVersion) } }