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 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 c5807505..81a687b8 100644 --- a/src/test/e2e/zarf_test.go +++ b/src/test/e2e/zarf_test.go @@ -5,9 +5,11 @@ package test import ( + "fmt" "strings" "testing" + "github.com/defenseunicorns/zarf/src/pkg/utils/exec" "github.com/stretchr/testify/require" ) @@ -20,3 +22,53 @@ 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") } + +func TestZarfToolsVersions(t *testing.T) { + 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: "CraneVersion", + description: "zarf tools crane version", + args: args{tool: "crane", toolRepo: "github.com/google/go-containerregistry"}, + }, + { + name: "SyftVersion", + description: "zarf tools syft version", + args: args{tool: "syft", toolRepo: "github.com/anchore/syft"}, + }, + { + name: "ArchiverVersion", + description: "zarf tools archiver version", + args: args{tool: "archiver", toolRepo: "github.com/mholt/archiver/v3"}, + }, + } + + for _, tt := range tests { + cmdArgs := fmt.Sprintf("zarf tools %s version", tt.args.tool) + res, stdErr, err := e2e.UDS(strings.Split(cmdArgs, " ")...) + require.NoError(t, err) + + 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, "'")[1] + output := res + if res == "" { + output = stdErr + } + require.Contains(t, output, toolVersion) + } +}