Skip to content

chore(Makefile): update golden files as part of make gen #17039

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 1 commit into from
Mar 21, 2025
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
11 changes: 4 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,15 @@ jobs:
popd
- name: make gen
# no `-j` flag as `make` fails with:
# coderd/rbac/object_gen.go:1:1: syntax error: package statement must be first
run: "make --output-sync -B gen"

- name: make update-golden-files
run: |
# Remove golden files to detect discrepancy in generated files.
make clean/golden-files
# Notifications require DB, we could start a DB instance here but
# let's just restore for now.
git checkout -- coderd/notifications/testdata/rendered-templates
# As above, skip `-j` flag.
make --output-sync -B update-golden-files
# no `-j` flag as `make` fails with:
# coderd/rbac/object_gen.go:1:1: syntax error: package statement must be first
make --output-sync -B gen
- name: Check for unstaged files
run: ./scripts/check_unstaged.sh
Expand Down
28 changes: 17 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,24 @@ GEN_FILES := \
agent/agentcontainers/dcspec/dcspec_gen.go

# all gen targets should be added here and to gen/mark-fresh
gen: gen/db $(GEN_FILES)
gen: gen/db gen/golden-files $(GEN_FILES)
.PHONY: gen

gen/db: $(DB_GEN_FILES)
.PHONY: gen/db

gen/golden-files: \
cli/testdata/.gen-golden \
coderd/.gen-golden \
coderd/notifications/.gen-golden \
enterprise/cli/testdata/.gen-golden \
enterprise/tailnet/testdata/.gen-golden \
helm/coder/tests/testdata/.gen-golden \
helm/provisioner/tests/testdata/.gen-golden \
provisioner/terraform/testdata/.gen-golden \
tailnet/testdata/.gen-golden
.PHONY: gen/golden-files

# 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:
Expand Down Expand Up @@ -743,16 +755,10 @@ coderd/apidoc/swagger.json: node_modules/.installed site/node_modules/.installed
cd site/
pnpm exec biome format --write ../docs/manifest.json ../coderd/apidoc/swagger.json

update-golden-files: \
cli/testdata/.gen-golden \
coderd/.gen-golden \
coderd/notifications/.gen-golden \
enterprise/cli/testdata/.gen-golden \
enterprise/tailnet/testdata/.gen-golden \
helm/coder/tests/testdata/.gen-golden \
helm/provisioner/tests/testdata/.gen-golden \
provisioner/terraform/testdata/.gen-golden \
tailnet/testdata/.gen-golden
update-golden-files:
echo 'WARNING: This target is deprecated. Use "make gen/golden-files" instead.' 2>&1
echo 'Running "make gen/golden-files"' 2>&1
make gen/golden-files
.PHONY: update-golden-files

clean/golden-files:
Expand Down
6 changes: 3 additions & 3 deletions cli/clitest/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// UpdateGoldenFiles indicates golden files should be updated.
// To update the golden files:
// make update-golden-files
// make gen/golden-files
var UpdateGoldenFiles = flag.Bool("update", false, "update .golden files")

var timestampRegex = regexp.MustCompile(`(?i)\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d+)?(Z|[+-]\d+:\d+)`)
Expand Down Expand Up @@ -113,12 +113,12 @@ func TestGoldenFile(t *testing.T, fileName string, actual []byte, replacements m
}

expected, err := os.ReadFile(goldenPath)
require.NoError(t, err, "read golden file, run \"make update-golden-files\" and commit the changes")
require.NoError(t, err, "read golden file, run \"make gen/golden-files\" and commit the changes")

expected = normalizeGoldenFile(t, expected)
require.Equal(
t, string(expected), string(actual),
"golden file mismatch: %s, run \"make update-golden-files\", verify and commit the changes",
"golden file mismatch: %s, run \"make gen/golden-files\", verify and commit the changes",
goldenPath,
)
}
Expand Down
8 changes: 4 additions & 4 deletions coderd/insights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ func TestTemplateInsights_Golden(t *testing.T) {
}

f, err := os.Open(goldenFile)
require.NoError(t, err, "open golden file, run \"make update-golden-files\" and commit the changes")
require.NoError(t, err, "open golden file, run \"make gen/golden-files\" and commit the changes")
defer f.Close()
var want codersdk.TemplateInsightsResponse
err = json.NewDecoder(f).Decode(&want)
Expand All @@ -1311,7 +1311,7 @@ func TestTemplateInsights_Golden(t *testing.T) {
}),
}
// Use cmp.Diff here because it produces more readable diffs.
assert.Empty(t, cmp.Diff(want, report, cmpOpts...), "golden file mismatch (-want +got): %s, run \"make update-golden-files\", verify and commit the changes", goldenFile)
assert.Empty(t, cmp.Diff(want, report, cmpOpts...), "golden file mismatch (-want +got): %s, run \"make gen/golden-files\", verify and commit the changes", goldenFile)
})
}
})
Expand Down Expand Up @@ -2076,7 +2076,7 @@ func TestUserActivityInsights_Golden(t *testing.T) {
}

f, err := os.Open(goldenFile)
require.NoError(t, err, "open golden file, run \"make update-golden-files\" and commit the changes")
require.NoError(t, err, "open golden file, run \"make gen/golden-files\" and commit the changes")
defer f.Close()
var want codersdk.UserActivityInsightsResponse
err = json.NewDecoder(f).Decode(&want)
Expand All @@ -2092,7 +2092,7 @@ func TestUserActivityInsights_Golden(t *testing.T) {
}),
}
// Use cmp.Diff here because it produces more readable diffs.
assert.Empty(t, cmp.Diff(want, report, cmpOpts...), "golden file mismatch (-want +got): %s, run \"make update-golden-files\", verify and commit the changes", goldenFile)
assert.Empty(t, cmp.Diff(want, report, cmpOpts...), "golden file mismatch (-want +got): %s, run \"make gen/golden-files\", verify and commit the changes", goldenFile)
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
hello = "localhost"

from = "system@coder.com"
hint = "run \"DB=ci make update-golden-files\" and commit the changes"
hint = "run \"DB=ci make gen/golden-files\" and commit the changes"
)

tests := []struct {
Expand Down
6 changes: 3 additions & 3 deletions enterprise/tailnet/pgcoord_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

// UpdateGoldenFiles indicates golden files should be updated.
// To update the golden files:
// make update-golden-files
// make gen/golden-files
var UpdateGoldenFiles = flag.Bool("update", false, "update .golden files")

// TestHeartbeats_Cleanup tests the cleanup loop
Expand Down Expand Up @@ -316,11 +316,11 @@ func TestDebugTemplate(t *testing.T) {
}

expected, err := os.ReadFile(goldenPath)
require.NoError(t, err, "read golden file, run \"make update-golden-files\" and commit the changes")
require.NoError(t, err, "read golden file, run \"make gen/golden-files\" and commit the changes")

require.Equal(
t, string(expected), string(actual),
"golden file mismatch: %s, run \"make update-golden-files\", verify and commit the changes",
"golden file mismatch: %s, run \"make gen/golden-files\", verify and commit the changes",
goldenPath,
)
}
Expand Down
4 changes: 2 additions & 2 deletions provisioner/terraform/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func diffFileSystem(t *testing.T, fs afero.Fs) {
}

want, err := os.ReadFile(goldenFile)
require.NoError(t, err, "open golden file, run \"make update-golden-files\" and commit the changes")
assert.Empty(t, cmp.Diff(want, actual), "golden file mismatch (-want +got): %s, run \"make update-golden-files\", verify and commit the changes", goldenFile)
require.NoError(t, err, "open golden file, run \"make gen/golden-files\" and commit the changes")
assert.Empty(t, cmp.Diff(want, actual), "golden file mismatch (-want +got): %s, run \"make gen/golden-files\", verify and commit the changes", goldenFile)
}

func dumpFileSystem(t *testing.T, fs afero.Fs) []byte {
Expand Down
6 changes: 3 additions & 3 deletions tailnet/coordinator_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// UpdateGoldenFiles indicates golden files should be updated.
// To update the golden files:
// make update-golden-files
// make gen/golden-files
var UpdateGoldenFiles = flag.Bool("update", false, "update .golden files")

func TestDebugTemplate(t *testing.T) {
Expand Down Expand Up @@ -64,11 +64,11 @@ func TestDebugTemplate(t *testing.T) {
}

expected, err := os.ReadFile(goldenPath)
require.NoError(t, err, "read golden file, run \"make update-golden-files\" and commit the changes")
require.NoError(t, err, "read golden file, run \"make gen/golden-files\" and commit the changes")

require.Equal(
t, string(expected), string(actual),
"golden file mismatch: %s, run \"make update-golden-files\", verify and commit the changes",
"golden file mismatch: %s, run \"make gen/golden-files\", verify and commit the changes",
goldenPath,
)
}
Loading