Skip to content

feat: Add golden files to test cli help output #4897

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

Merged
merged 6 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Separate make command -> make update-golden-files
  • Loading branch information
mafredri committed Nov 4, 2022
commit 1b4dbe98d5a61125ee23dbca04ded0af7c9725fa
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ gotests.coverage
.gitpod.yml
.DS_Store

# Make target for updating golden files.
cli/testdata/.gen-golden

# Front-end ignore
.next/
site/.eslintcache
Expand Down
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,14 @@ gen: \
coderd/database/querier.go \
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
site/src/api/typesGenerated.ts \
cli/testdata/golden
site/src/api/typesGenerated.ts
.PHONY: gen

# Mark all generated files as fresh so make thinks they're up-to-date. This is
# used during releases so we don't run generation scripts.
gen/mark-fresh:
files="coderd/database/dump.sql coderd/database/querier.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts"
files=($$files cli/testdata/*.golden)
for file in "$${files[@]}"; do
for file in $$files; do
echo "$$file"
if [ ! -f "$$file" ]; then
echo "File '$$file' does not exist"
Expand Down Expand Up @@ -445,9 +443,14 @@ site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find codersdk
cd site
yarn run format:types

cli/testdata/golden: $(wildcard cli/testdata/*.golden)
update-golden-files: cli/testdata/.gen-golden
.PHONY: update-golden-files

cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) \
$(shell find . -not -path './vendor/*' -type f -name '*.go')

go test ./cli -run=TestCommandHelp -update
.PHONY: cli/testdata/golden
touch "$@"

test: test-clean
gotestsum -- -v -short ./...
Expand Down
4 changes: 2 additions & 2 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func TestCommandHelp(t *testing.T) {
}

want, err := os.ReadFile(gf)
require.NoError(t, err, "read golden file, run \"make gen\" and commit the changes")
require.NoError(t, err, "read golden file, run \"make update-golden-files\" and commit the changes")
got := buf.Bytes()
require.Equal(t, string(want), string(got), "golden file mismatch: %s, run \"make gen\", verify and commit the changes", gf)
require.Equal(t, string(want), string(got), "golden file mismatch: %s, run \"make update-golden-files\", verify and commit the changes", gf)
})
}
}
Expand Down