Skip to content

Commit

Permalink
Merge branch 'main' into remove/k8s-sa
Browse files Browse the repository at this point in the history
  • Loading branch information
Noxsios authored May 23, 2024
2 parents 7c791e7 + 31d56e4 commit c1a7744
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 12 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Run coverage
run: go test -race -coverprofile=coverage.out -covermode=atomic

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # v4.4.1
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Setup golang
uses: ./.github/actions/golang

- name: Run unit tests
run: make test-unit
run: make test-unit

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # v4.4.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ zarf-sbom/
test-*.txt
__debug_bin
.netlify
coverage.out
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ test-upgrade: ## Run the Zarf CLI E2E tests for an external registry and cluster

.PHONY: test-unit
test-unit: ## Run unit tests
cd src/pkg && go test ./... -failfast -v -timeout 30m
cd src/internal && go test ./... -failfast -v timeout 30m
cd src/extensions/bigbang && go test ./. -failfast -v timeout 30m
go test -failfast -v -coverprofile=coverage.out -covermode=atomic $$(go list ./... | grep -v '^github.com/defenseunicorns/zarf/src/test' | grep -v 'github.com/defenseunicorns/zarf/src/extensions/bigbang/test')

# INTERNAL: used to test that a dev has ran `make docs-and-schema` in their PR
test-docs-and-schema:
Expand Down
175 changes: 175 additions & 0 deletions src/pkg/packager/creator/compose_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package creator contains functions for creating Zarf packages.
package creator

import (
"testing"

"github.com/defenseunicorns/zarf/src/types"
"github.com/stretchr/testify/require"
)

func TestComposeComponents(t *testing.T) {
t.Parallel()

tests := []struct {
name string
pkg types.ZarfPackage
flavor string
expectedPkg types.ZarfPackage
expectedErr string
}{
{
name: "filter by architecture match",
pkg: types.ZarfPackage{
Metadata: types.ZarfMetadata{Architecture: "amd64"},
Components: []types.ZarfComponent{
{
Name: "component1",
Only: types.ZarfComponentOnlyTarget{
Cluster: types.ZarfComponentOnlyCluster{
Architecture: "amd64",
},
},
},
{
Name: "component2",
Only: types.ZarfComponentOnlyTarget{
Cluster: types.ZarfComponentOnlyCluster{
Architecture: "amd64",
},
},
},
},
},
expectedPkg: types.ZarfPackage{
Components: []types.ZarfComponent{
{Name: "component1"},
{Name: "component2"},
},
},
expectedErr: "",
},
{
name: "filter by architecture mismatch",
pkg: types.ZarfPackage{
Metadata: types.ZarfMetadata{Architecture: "amd64"},
Components: []types.ZarfComponent{
{
Name: "component1",
Only: types.ZarfComponentOnlyTarget{
Cluster: types.ZarfComponentOnlyCluster{
Architecture: "amd64",
},
},
},
{
Name: "component2",
Only: types.ZarfComponentOnlyTarget{
Cluster: types.ZarfComponentOnlyCluster{
Architecture: "arm64",
},
},
},
},
},
expectedPkg: types.ZarfPackage{
Components: []types.ZarfComponent{
{Name: "component1"},
},
},
expectedErr: "",
},
{
name: "filter by flavor match",
pkg: types.ZarfPackage{
Metadata: types.ZarfMetadata{Architecture: "amd64"},
Components: []types.ZarfComponent{
{
Name: "component1",
Only: types.ZarfComponentOnlyTarget{
Flavor: "default",
},
},
{
Name: "component2",
Only: types.ZarfComponentOnlyTarget{
Flavor: "default",
},
},
},
},
flavor: "default",
expectedPkg: types.ZarfPackage{
Components: []types.ZarfComponent{
{Name: "component1"},
{Name: "component2"},
},
},
expectedErr: "",
},
{
name: "filter by flavor mismatch",
pkg: types.ZarfPackage{
Metadata: types.ZarfMetadata{Architecture: "amd64"},
Components: []types.ZarfComponent{
{
Name: "component1",
Only: types.ZarfComponentOnlyTarget{
Flavor: "default",
},
},
{
Name: "component2",
Only: types.ZarfComponentOnlyTarget{
Flavor: "special",
},
},
},
},
flavor: "default",
expectedPkg: types.ZarfPackage{
Components: []types.ZarfComponent{
{Name: "component1"},
},
},
expectedErr: "",
},
{
name: "no architecture set error",
pkg: types.ZarfPackage{
Components: []types.ZarfComponent{
{
Name: "component1",
Only: types.ZarfComponentOnlyTarget{
Flavor: "default",
},
},
},
},
flavor: "default",
expectedPkg: types.ZarfPackage{},
expectedErr: "cannot build import chain: architecture must be provided",
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

pkg, _, err := ComposeComponents(tt.pkg, tt.flavor)

if tt.expectedErr == "" {
require.NoError(t, err)
require.Equal(t, tt.expectedPkg.Components, pkg.Components)
return
}

require.EqualError(t, err, tt.expectedErr)
require.Empty(t, tt.expectedPkg)
})
}
}

0 comments on commit c1a7744

Please sign in to comment.