Skip to content

Commit

Permalink
chore: ensure vendored tools versions print out (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanHoladay authored May 6, 2024
1 parent 5285562 commit 61ae6d2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions src/test/e2e/zarf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
package test

import (
"fmt"
"strings"
"testing"

"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/stretchr/testify/require"
)

Expand All @@ -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)
}
}

0 comments on commit 61ae6d2

Please sign in to comment.