Skip to content

Commit 71f6a8f

Browse files
committed
dev: add update-golden goal
Signed-off-by: Nikita Pivkin <nikita.pivkin@smartforce.io>
1 parent bf330b1 commit 71f6a8f

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@ SED = gsed
77
BATS_LIB_PATH = /opt/homebrew/lib
88
endif
99

10+
BATS_ENV := BATS_LIB_PATH=$(BATS_LIB_PATH) \
11+
GITHUB_REPOSITORY_OWNER=aquasecurity \
12+
TRIVY_CACHE_DIR=.cache \
13+
TRIVY_DISABLE_VEX_NOTICE=true \
14+
TRIVY_DEBUG=true
15+
16+
BATS_FLAGS := --recursive --timing --verbose-run .
17+
1018
.PHONY: test
1119
test:
1220
mkdir -p .cache
13-
BATS_LIB_PATH=$(BATS_LIB_PATH) GITHUB_REPOSITORY_OWNER=aquasecurity\
14-
TRIVY_CACHE_DIR=.cache TRIVY_DISABLE_VEX_NOTICE=true TRIVY_DEBUG=true\
15-
bats --recursive --timing --verbose-run .
21+
$(BATS_ENV) bats $(BATS_FLAGS)
22+
23+
.PHONY: update-golden
24+
update-golden:
25+
mkdir -p .cache
26+
UPDATE_GOLDEN=1 $(BATS_ENV) bats $(BATS_FLAGS)
1627

1728
bump-trivy:
1829
@[ $$NEW_VERSION ] || ( echo "env 'NEW_VERSION' is not set"; exit 1 )

test/test.bats

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ function compare_files() {
5757
remove_github_fields "$file1"
5858
remove_github_fields "$file2"
5959

60-
run diff "$file1" "$file2"
61-
echo "$output"
62-
assert_files_equal "$file1" "$file2"
60+
if [ "${UPDATE_GOLDEN}" = "1" ]; then
61+
cp "$file1" "$file2"
62+
echo "Updated golden file: $file2"
63+
else
64+
run diff "$file1" "$file2"
65+
echo "$output"
66+
assert_files_equal "$file1" "$file2"
67+
fi
68+
69+
rm -f "$file1"
6370
}
6471

6572
@test "trivy repo with securityCheck secret only" {

0 commit comments

Comments
 (0)