// Package golden compares test output against stored golden files, rewriting// them instead when the PLUMB_GOLDEN_UPDATE environment variable is set.
package goldenimport ()// updateEnv, when set to a non-empty value, switches the helpers from comparing// against golden files to rewriting them.constupdateEnv = "PLUMB_GOLDEN_UPDATE"// updating reports whether golden files should be rewritten this run.func () bool {returnos.Getenv(updateEnv) != ""}// Check compares got against the golden file at path and fails the test on a// mismatch. When updating() is true it rewrites the file instead (creating it if// absent); otherwise a missing file is fatal and names the env var to set.func ( *testing.T, , string) { .Helper()ifupdating() {if := writefile.Write(, ); != nil { .Fatalf("writing golden %s: %v", , ) }return } , := os.ReadFile()if != nil { .Fatalf("reading golden %s (run with %s=1 to create it): %v", , updateEnv, ) }if != string() { .Errorf("output differs from golden %s:\n--- got ---\n%s\n--- want ---\n%s", , , ) }}
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)