Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
66497a2
perf(ci): use fixed version ldflags for tests to enable GOCACHE hits
davdhacs Mar 25, 2026
0bdca75
perf(ci): stabilize file mtimes for Go test cache
davdhacs Mar 24, 2026
0af36f0
perf(ci): also stabilize directory mtimes for test cache
davdhacs Mar 26, 2026
dfff6f5
perf(ci): stop over-separating GOCACHE for matrix variants that share…
davdhacs Mar 24, 2026
dc74d14
fix(ci): add key-suffix for unit-test GOTAGS matrix and scanner GOARCH
davdhacs Mar 24, 2026
8fae846
style: add parentheses to key-suffix conditional for clarity
davdhacs Mar 24, 2026
8fbd5e5
revert: keep operator branding key-suffix (PR #19417 will refactor this)
davdhacs Mar 25, 2026
76892da
chore: add comment explaining race-only cache key separation
davdhacs Mar 25, 2026
841d0ad
empty: warm run with rebased combined branch
davdhacs Mar 28, 2026
8fdaa3a
ci: temporarily always save GOCACHE for testing on PR branch (remove …
davdhacs Mar 28, 2026
ab64892
empty: warm run after cache save
davdhacs Mar 28, 2026
4e792fc
perf(ci): remove container from unit-tests jobs, run on host
davdhacs Mar 29, 2026
b3fd3ff
fix: install bats, fix postgres role, keep openshift-ci in container
davdhacs Mar 29, 2026
7d7d8c8
fix: install bats libs to /usr/lib/node_modules to match test helpers
davdhacs Mar 29, 2026
2ea9954
fix: address test failures from container removal
davdhacs Mar 29, 2026
c51eb95
fix: add host runner path prefix for rate limited logger
davdhacs Mar 29, 2026
b05f21b
fix: escape & in bash replacement strings for bash 5.2+
davdhacs Mar 29, 2026
41fe559
fix: override GOTOOLCHAIN=local from setup-go
davdhacs Mar 29, 2026
bed59cd
empty: warm run after successful seed
davdhacs Mar 29, 2026
e15a29e
fix: handle yq v4 multi-doc separators in netpol bats tests
davdhacs Mar 29, 2026
3f82c38
perf(ci): split go unit tests into 3 shards (pkg, central, rest)
davdhacs Mar 29, 2026
42b76e7
fix: exclude sensor/tests and operator/tests from rest shard
davdhacs Mar 29, 2026
faf9004
empty: warm run with all 3 shard caches saved
davdhacs Mar 29, 2026
c7efb58
perf(ci): separate integration tests job, skip bench on PRs
davdhacs Mar 29, 2026
64444f8
perf(ci): split go-postgres into main/migrator shards
davdhacs Mar 29, 2026
981344d
empty: warm run with all shard caches
davdhacs Mar 29, 2026
a14c6a3
perf(ci): split integration/operator tests, enable integration caching
davdhacs Mar 29, 2026
4525f53
fix: remove junit report from operator integration (no test log)
davdhacs Mar 29, 2026
6e14b45
empty: warm run with all caches including operator-integration
davdhacs Mar 29, 2026
4f8206a
perf(ci): split go tests into 5 shards for smaller caches
davdhacs Mar 30, 2026
4349ae5
empty: warm run with 5-way shard caches
davdhacs Mar 30, 2026
a446d62
perf(ci): experiment — skip GOMODCACHE for pkg-helm shard
davdhacs Mar 30, 2026
942cc0f
perf(ci): skip GOMODCACHE for all go test shards
davdhacs Mar 30, 2026
c1044a9
perf(ci): skip GOMODCACHE + shallow checkout for all Go test jobs
davdhacs Mar 30, 2026
fdb4653
fix: restore GOMODCACHE for operator-integration (needs protoc tools)
davdhacs Mar 30, 2026
e17999c
perf(ci): skip GOMODCACHE for local-roxctl-tests
davdhacs Mar 30, 2026
e223936
perf(ci): split local-roxctl-tests into dev/release shards
davdhacs Mar 30, 2026
10a07a2
empty: warm run with roxctl shard caches
davdhacs Mar 30, 2026
f39a036
perf(ci): remove container from ui-component, use setup-node
davdhacs Mar 30, 2026
ad30746
perf(ci): use cypress-io/github-action for ui-component tests
davdhacs Mar 30, 2026
ae2e769
perf(ci): bypass make deps/build-prep for test jobs
davdhacs Mar 30, 2026
f58b26a
fix: restore make targets for go-postgres, fix ui-component junit
davdhacs Mar 30, 2026
4c81839
perf(ci): add SKIP_DEPS to bypass go mod tidy in test jobs
davdhacs Mar 30, 2026
4a3925f
perf(ci): disable Cypress video, upload artifacts only on failure
davdhacs Mar 30, 2026
869af28
refactor: keep skip-mod-cache default false, explicit true on test jobs
davdhacs Mar 30, 2026
67bae80
perf(ci): adopt cache-mod approach from #19688
davdhacs Mar 30, 2026
4e9c8ad
empty: trigger CI for cold run with cache-mod approach
davdhacs Mar 30, 2026
73ba0fe
trigger: add comment to force workflow run
davdhacs Mar 30, 2026
4b8edf2
chore: clean trigger comment
davdhacs Mar 30, 2026
5648e38
fix: remove duplicate integration/helm steps from go shards
davdhacs Mar 30, 2026
ef394a2
fix: use := for SCANNER_DIR, remove unused matrix.variant.env
davdhacs Mar 30, 2026
23a8a0f
perf: make SCANNER_DIR lazy — only download when proto targets run
davdhacs Mar 30, 2026
51abc01
docs: explain bash 5.2 ampersand escaping in XML replacement
davdhacs Mar 30, 2026
5e8e46b
fix: fail fast on postgres readiness timeout, increase to 60s
davdhacs Mar 30, 2026
74e56e5
fix: use tee -a in migrator target to preserve main shard output
davdhacs Mar 30, 2026
581f56d
fix: preserve yq exit status in yq_multidoc helper
davdhacs Mar 30, 2026
88cc868
fix: assert specific errors in zip path traversal test
davdhacs Mar 30, 2026
c8ca344
fix: set BUILD_TAG for operator helm tests (avoids git describe)
davdhacs Mar 30, 2026
1f31808
perf(ci): adopt latest #19688 — remove GOMODCACHE entirely
davdhacs Mar 30, 2026
4464bdf
fix: set BUILD_TAG on operator integration tests too
davdhacs Mar 31, 2026
ca27ddf
fix: use /.dockerenv instead of GITHUB_ACTIONS for container detectio…
davdhacs Mar 31, 2026
6d9dd2a
chore: remove circular TestContainerDetection
davdhacs Mar 31, 2026
83f47d9
empty: re-trigger CI after operator-integration fix
davdhacs Mar 31, 2026
7dc8c1c
Merge origin/master into davdhacs/matrix-unittests
davdhacs Mar 31, 2026
b9c014f
fix: host-runner compatibility for tests and scripts
davdhacs Mar 31, 2026
f153542
Merge remote-tracking branch 'origin/master' into davdhacs/matrix-uni…
davdhacs Mar 31, 2026
c42ca78
fix(ci): address shellcheck warnings in unit-tests workflow
davdhacs Mar 31, 2026
9f2eb95
fix(ci): fix shellcheck directive syntax
davdhacs Mar 31, 2026
3f50506
Merge remote-tracking branch 'origin/master' into davdhacs/host-runne…
davdhacs Mar 31, 2026
fe90602
Merge remote-tracking branch 'origin/master' into davdhacs/host-runne…
davdhacs Apr 1, 2026
0abf513
Merge remote-tracking branch 'origin/master' into davdhacs/matrix-uni…
davdhacs Apr 1, 2026
58ea483
fix: use sed instead of grep -v in yq_multidoc
davdhacs Apr 1, 2026
11e1696
Merge remote-tracking branch 'origin/davdhacs/host-runner-test-fixes'…
davdhacs Apr 1, 2026
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
298 changes: 232 additions & 66 deletions .github/workflows/unit-tests.yaml

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,15 @@ config-controller-gen:
.PHONY: generated-srcs
generated-srcs: go-generated-srcs config-controller-gen

ifdef SKIP_DEPS
deps:
@echo "+ $@ (skipped via SKIP_DEPS)"
$(SILENT)touch deps
else
deps: $(shell find $(BASE_DIR) -name "go.sum")
@echo "+ $@"
$(SILENT)touch deps
endif

%/go.sum: %/go.mod
$(SILENT)cd $*
Expand Down Expand Up @@ -554,11 +560,17 @@ sensor-pipeline-benchmark: build-prep test-prep
LOGLEVEL="panic" go test -bench=. -run=^# -benchtime=30s -count=5 ./sensor/tests/pipeline | tee $(CURDIR)/test-output/pipeline.results.txt

.PHONY: go-postgres-unit-tests
go-postgres-unit-tests: build-prep test-prep
go-postgres-unit-tests: go-postgres-unit-tests-main go-postgres-unit-tests-migrator

.PHONY: go-postgres-unit-tests-main
go-postgres-unit-tests-main: build-prep test-prep
set -o pipefail ; \
CGO_ENABLED=1 GOEXPERIMENT=cgocheck2 MUTEX_WATCHDOG_TIMEOUT_SECS=30 GOTAGS=$(GOTAGS),test,sql_integration scripts/go-test.sh -timeout 15m -race -cover -coverprofile test-output/coverage.out -v \
$(shell git grep -rl "//go:build sql_integration" central pkg tools | sed -e 's@^@./@g' | xargs -n 1 dirname | sort | uniq | xargs go list -tags sql_integration | grep -v '^github.com/stackrox/rox/tests$$' | grep -Ev $(UNIT_TEST_IGNORE)) \
| tee $(GO_TEST_OUTPUT_PATH)

.PHONY: go-postgres-unit-tests-migrator
go-postgres-unit-tests-migrator: build-prep test-prep
@# The -p 1 passed to go test is required to ensure that tests of different packages are not run in parallel, so as to avoid conflicts when interacting with the DB.
set -o pipefail ; \
CGO_ENABLED=1 GOEXPERIMENT=cgocheck2 MUTEX_WATCHDOG_TIMEOUT_SECS=30 GOTAGS=$(GOTAGS),test,sql_integration scripts/go-test.sh -p 1 -race -cover -coverprofile test-output/migrator-coverage.out -v \
Expand Down Expand Up @@ -602,7 +614,7 @@ test: go-unit-tests ui-test shell-unit-tests
.PHONY: integration-unit-tests
integration-unit-tests: build-prep test-prep
set -o pipefail ; \
GOTAGS=$(GOTAGS),test,integration scripts/go-test.sh -count=1 -v \
GOTAGS=$(GOTAGS),test,integration scripts/go-test.sh -v \
$(shell go list ./... | grep "registries\|scanners\|notifiers") \
| tee $(GO_TEST_OUTPUT_PATH)

Expand Down
18 changes: 0 additions & 18 deletions pkg/containers/detection_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion pkg/logging/rate_limited_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ const (
localFilePathPrefix = "github.com/stackrox/stackrox/"
filePathPrefix = "github.com/stackrox/rox/"
githubPathPrefix = "/__w/stackrox/stackrox/"
githubHostPrefix = "/home/runner/work/stackrox/stackrox/"
)

func getTrimmedFilePath(path string) string {
prefixes := []string{filePathPrefix, localFilePathPrefix, githubPathPrefix}
prefixes := []string{filePathPrefix, localFilePathPrefix, githubPathPrefix, githubHostPrefix}
for _, prefix := range prefixes {
prefixToCut := strings.Index(path, prefix)
if prefixToCut >= 0 {
Expand Down
7 changes: 5 additions & 2 deletions roxctl/common/zipdownload/download_zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zipdownload
import (
"archive/zip"
"bytes"
"errors"
"io/fs"
"os"
"path/filepath"
Expand Down Expand Up @@ -208,7 +209,9 @@ func TestExtractZipToFolder_PreventPathTraversal(t *testing.T) {

for _, path := range checkPaths {
_, err := os.Stat(path)
// Expect "no such file or directory" - meaning the file wasn't created
assert.ErrorIs(t, err, fs.ErrNotExist, "Malicious file should not exist at %s", path)
// File must not exist. On non-root runners, paths under /root/ return
// ErrPermission instead of ErrNotExist — both confirm the file wasn't written.
assert.True(t, errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission),
"Malicious file should not exist at %s, got: %v", path, err)
Comment on lines +212 to +215
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Narrow ErrPermission handling to avoid masking traversal regressions.

At Line 214, allowing fs.ErrPermission for all paths makes this defense-in-depth check too permissive. For paths that are expected to be readable in CI (parentDir, grandParentDir, /tmp, /etc), this can hide a real escape side effect.

Proposed tightening
 for _, path := range checkPaths {
 	_, err := os.Stat(path)
-	// File must not exist. On non-root runners, paths under /root/ return
-	// ErrPermission instead of ErrNotExist — both confirm the file wasn't written.
-	assert.True(t, errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission),
-		"Malicious file should not exist at %s, got: %v", path, err)
+	// `/root` may be non-traversable on non-root runners, so ErrPermission is acceptable there.
+	if strings.HasPrefix(path, "/root/") {
+		assert.True(t, errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission),
+			"Malicious file should not exist at %s, got: %v", path, err)
+		continue
+	}
+	assert.ErrorIs(t, err, fs.ErrNotExist, "Malicious file should not exist at %s", path)
 }

As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@roxctl/common/zipdownload/download_zip_test.go` around lines 212 - 215, The
current assertion in the test allows fs.ErrPermission for all paths which can
mask path-traversal regressions; change the check in the test that verifies the
file does not exist (the assert.True using errors.Is(err, fs.ErrNotExist) ||
errors.Is(err, fs.ErrPermission)) so that fs.ErrPermission is only treated as
acceptable for specific well-known safe paths (e.g., parentDir, grandParentDir,
"/tmp", "/etc"); for all other paths require errors.Is(err, fs.ErrNotExist).
Locate the failing assertion in download_zip_test.go and implement a conditional
that checks the path variable against those safe directories and only ORs in
errors.Is(..., fs.ErrPermission) for them, otherwise assert ErrNotExist.

}
}
16 changes: 10 additions & 6 deletions scripts/ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2322,12 +2322,16 @@ _EO_SUITE_HEADER_
local result="${lines[1]}"
local details="${lines[2]}"

# XML escape description
description="${description//&/&}"
description="${description//\"/"}"
description="${description//\'/'}"
description="${description//</&lt;}"
description="${description//>/&gt;}"
# XML escape description.
# \& is required: bash 5.2+ treats & in ${var//pat/repl} as the
# matched text (like sed), so without \& the & is replaced by the
# match itself. \& works on all bash versions (4.4–5.3 verified).
# CI container had bash 5.1 (UBI9); ubuntu-latest has bash 5.2+.
description="${description//&/\&amp;}"
description="${description//\"/\&quot;}"
description="${description//\'/\&#39;}"
description="${description//</\&lt;}"
description="${description//>/\&gt;}"

cat << _EO_CASE_HEADER_ >> "${junit_file}"
<testcase name="${description}" classname="${class}">
Expand Down
85 changes: 49 additions & 36 deletions scripts/go-tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,56 @@ die() {
}

RACE="${RACE:-false}"

x_defs=()
x_def_errors=()

while read -r line || [[ -n "$line" ]]; do
if [[ "$line" =~ ^[[:space:]]*$ ]]; then
continue
elif [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+(.*)[[:space:]]*$ ]]; then
var="${BASH_REMATCH[1]}"
def="${BASH_REMATCH[2]}"
eval "status_${var}=$(printf '%q' "$def")"
else
die "Malformed status.sh output line ${line}"
fi
done < <(cd "${SCRIPT_DIR}/.."; ./status.sh)

while read -r line || [[ -n "$line" ]]; do
if [[ "$line" =~ ^[[:space:]]*$ ]]; then
continue
elif [[ "$line" =~ ^([^:]+):([[:digit:]]+):[[:space:]]*(var[[:space:]]+)?([^[:space:]]+)[[:space:]].*//XDef:([^[:space:]]+)[[:space:]]*$ ]]; then
go_file="${BASH_REMATCH[1]}"
go_line="${BASH_REMATCH[2]}"
go_var="${BASH_REMATCH[4]}"
status_var="${BASH_REMATCH[5]}"

varname="status_${status_var}"
[[ -n "${!varname}" ]] || x_def_errors+=(
"Variable ${go_var} defined in ${go_file}:${go_line} references status var ${status_var} that is not part of the status.sh output"
)
go_package="$(cd "${SCRIPT_DIR}/.."; go list -e "./$(dirname "$go_file")")"

x_defs+=(-X "\"${go_package}.${go_var}=${!varname}\"")
REPO_ROOT="${SCRIPT_DIR}/.."

if [[ "$TOOL" == "test" ]]; then
# Use fixed version strings for tests. Stable ldflags = stable link ActionIDs
# = Go test cache hits across commits. Tests don't need real version info.
VERSION_PKG="github.com/stackrox/rox/pkg/version/internal"
x_defs=(
-X "\"${VERSION_PKG}.MainVersion=0.0.0-test\""
-X "\"${VERSION_PKG}.CollectorVersion=0.0.0\""
-X "\"${VERSION_PKG}.ScannerVersion=0.0.0\""
-X "\"${VERSION_PKG}.FactVersion=0.0.0\""
)
else
x_defs=()
x_def_errors=()

while read -r line || [[ -n "$line" ]]; do
if [[ "$line" =~ ^[[:space:]]*$ ]]; then
continue
elif [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+(.*)[[:space:]]*$ ]]; then
var="${BASH_REMATCH[1]}"
def="${BASH_REMATCH[2]}"
eval "status_${var}=$(printf '%q' "$def")"
else
die "Malformed status.sh output line ${line}"
fi
done < <(cd "${REPO_ROOT}"; ./status.sh)

while read -r line || [[ -n "$line" ]]; do
if [[ "$line" =~ ^[[:space:]]*$ ]]; then
continue
elif [[ "$line" =~ ^([^:]+):([[:digit:]]+):[[:space:]]*(var[[:space:]]+)?([^[:space:]]+)[[:space:]].*//XDef:([^[:space:]]+)[[:space:]]*$ ]]; then
go_file="${BASH_REMATCH[1]}"
go_line="${BASH_REMATCH[2]}"
go_var="${BASH_REMATCH[4]}"
status_var="${BASH_REMATCH[5]}"

varname="status_${status_var}"
[[ -n "${!varname}" ]] || x_def_errors+=(
"Variable ${go_var} defined in ${go_file}:${go_line} references status var ${status_var} that is not part of the status.sh output"
)
go_package="$(cd "${REPO_ROOT}"; go list -e "./$(dirname "$go_file")")"

x_defs+=(-X "\"${go_package}.${go_var}=${!varname}\"")
fi
done < <(git -C "${REPO_ROOT}" grep -n '//XDef:' -- '*.go')
if [[ "${#x_def_errors[@]}" -gt 0 ]]; then
printf >&2 "%s\n" "${x_def_errors[@]}"
exit 1
fi
done < <(git -C "${SCRIPT_DIR}/.." grep -n '//XDef:' -- '*.go')
if [[ "${#x_def_errors[@]}" -gt 0 ]]; then
printf >&2 "%s\n" "${x_def_errors[@]}"
exit 1
fi

ldflags=("${x_defs[@]}")
Expand Down
8 changes: 8 additions & 0 deletions tests/roxctl/bats-tests/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ fi
load "${bats_helpers_root}/bats-support/load.bash"
load "${bats_helpers_root}/bats-assert/load.bash"

# yq_multidoc runs yq and strips --- document separators from output.
# yq 4.x adds separators between multi-doc results which shift assert_line indices.
yq_multidoc() {
local output
output=$(yq "$@") || return $?
sed '/^---$/d' <<< "$output"
}

# luname outputs uname in lowercase
luname() {
uname | tr '[:upper:]' '[:lower:]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ teardown() {
assert_line '2'

# Ensure that all yaml docs are of kind 'NetworkPolicy'
run yq e '.kind | ({"match": ., "doc": di})' "${ofile}"
run yq_multidoc e '.kind | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: NetworkPolicy'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: NetworkPolicy'
Expand All @@ -69,7 +69,7 @@ teardown() {
assert_line --index 5 'doc: 2'

# Ensure that all NetworkPolicies have the generated-by-stackrox label
run yq e '.metadata.labels | ({"match": ."network-policy-buildtime-generator.stackrox.io/generated", "doc": di})' "${ofile}"
run yq_multidoc e '.metadata.labels | ({"match": ."network-policy-buildtime-generator.stackrox.io/generated", "doc": di})' "${ofile}"
assert_line --index 0 'match: "true"'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: "true"'
Expand Down Expand Up @@ -99,7 +99,7 @@ teardown() {
assert_line '2'

# Ensure that all yaml docs are of kind 'NetworkPolicy'
run yq e '.kind | ({"match": ., "doc": di})' "${ofile}"
run yq_multidoc e '.kind | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: NetworkPolicy'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: NetworkPolicy'
Expand All @@ -108,7 +108,7 @@ teardown() {
assert_line --index 5 'doc: 2'

# Ensure that dns ports are properly set
run yq e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
run yq_multidoc e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: null'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: '${dns_port}
Expand All @@ -131,7 +131,7 @@ teardown() {
yaml_valid "$ofile"

# Ensure that dns ports are properly set
run yq e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
run yq_multidoc e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: null'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: '${dns_port}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,22 @@ teardown() {
assert_line '2'

# Ensure that all yaml docs are of kind 'NetworkPolicy'
run yq e '.kind | ({"match": ., "doc": di})' "${ofile}"
# Github actions run yq v3
run yq_multidoc e '.kind | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: NetworkPolicy'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: NetworkPolicy'
assert_line --index 3 'doc: 1'
assert_line --index 4 'match: NetworkPolicy'
assert_line --index 5 'doc: 2'

# yq v4 assertions
# assert_line --index 0 'match: NetworkPolicy'
# assert_line --index 1 'doc: 0'
# assert_line --index 2 '---'
# assert_line --index 3 'match: NetworkPolicy'
# assert_line --index 4 'doc: 1'
# assert_line --index 5 '---'
# assert_line --index 6 'match: NetworkPolicy'
# assert_line --index 7 'doc: 2'

# Ensure that all NetworkPolicies have the generated-by-stackrox label
run yq e '.metadata.labels | ({"match": ."network-policy-buildtime-generator.stackrox.io/generated", "doc": di})' "${ofile}"
run yq_multidoc e '.metadata.labels | ({"match": ."network-policy-buildtime-generator.stackrox.io/generated", "doc": di})' "${ofile}"
assert_line --index 0 'match: "true"'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: "true"'
assert_line --index 3 'doc: 1'
assert_line --index 4 'match: "true"'
assert_line --index 5 'doc: 2'

# yq v4 assertions
# assert_line --index 0 'match: "true"'
# assert_line --index 1 'doc: 0'
# assert_line --index 2 '---'
# assert_line --index 3 'match: "true"'
# assert_line --index 4 'doc: 1'
# assert_line --index 5 '---'
# assert_line --index 6 'match: "true"'
# assert_line --index 7 'doc: 2'
}

@test "roxctl-release netpol generate generates network policies with custom dns port" {
Expand All @@ -121,7 +100,7 @@ teardown() {
assert_line '2'

# Ensure that all yaml docs are of kind 'NetworkPolicy'
run yq e '.kind | ({"match": ., "doc": di})' "${ofile}"
run yq_multidoc e '.kind | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: NetworkPolicy'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: NetworkPolicy'
Expand All @@ -130,7 +109,7 @@ teardown() {
assert_line --index 5 'doc: 2'

# Ensure that dns ports are properly set
run yq e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
run yq_multidoc e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: null'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: '${dns_port}
Expand All @@ -153,7 +132,7 @@ teardown() {
yaml_valid "$ofile"

# Ensure that dns ports are properly set
run yq e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
run yq_multidoc e '.spec.egress[1].ports[0].port | ({"match": ., "doc": di})' "${ofile}"
assert_line --index 0 'match: null'
assert_line --index 1 'doc: 0'
assert_line --index 2 'match: '${dns_port}
Expand Down
Loading