Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ensure vendored tools versions print out #586

Merged
merged 4 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
decleaver marked this conversation as resolved.
Show resolved Hide resolved
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)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont love having "magic" array values, think you're fine if you update the contains to just version instead of version[4] and maybe just add [1] to line 37 for the helm version. I know its somewhat duplicative but probably worth testing the other tools too. Let me know what you think. Thanks again for uds-cli'ing!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried to remove some of the magicalness by doing what we talked about and then moving the tool version index reference out of the requires and up to where toolVersion is set. hopefully that makes things more readable.

Loading