Skip to content

acceptance: exit cleanly from -update when only regenerating outputs#5424

Draft
janniklasrose wants to merge 1 commit into
mainfrom
janniklasrose/test-update-exit-code
Draft

acceptance: exit cleanly from -update when only regenerating outputs#5424
janniklasrose wants to merge 1 commit into
mainfrom
janniklasrose/test-update-exit-code

Conversation

@janniklasrose
Copy link
Copy Markdown
Contributor

Changes

Why

The acceptance harness exited non-zero whenever -update applied a change: doComparison called AssertEqualTexts (which flags the test failed) and only overwrote the golden file afterwards. Since the test flag, not the write, drives the exit code, every regenerated file made go test ... -update exit 1 even though the update succeeded.

Regenerating outputs is the goal of -update, not a failure. Move the OverwriteMode write/remove handling into an early-return block so a successful update returns without marking the test failed; only genuine problems still fail (read errors via tryReading, write errors via require/testutil, and the "both files missing" case). The non-update comparison path is unchanged.

This lets generate-refschema drop its ignore_error: true workaround (and the &> /dev/null redirect that hid genuine errors), and makes test-update / test-update-templates / test-update-aws exit 0 on changes as intended.

Tests

┌───────────────────────────────────┬──────┬────────────────────────────────┐
│             Scenario              │ Exit │             Result             │
├───────────────────────────────────┼──────┼────────────────────────────────┤
│ -update, no change                │ 0    │ ✓ (unchanged)                  │
├───────────────────────────────────┼──────┼────────────────────────────────┤
│ -update, with change              │ 0    │ file updated correctly (was 1) │
├───────────────────────────────────┼──────┼────────────────────────────────┤
│ no -update, clean                 │ 0    │ ✓                              │
├───────────────────────────────────┼──────┼────────────────────────────────┤
│ no -update, drift                 │ 1    │ drift still detected ✓         │
├───────────────────────────────────┼──────┼────────────────────────────────┤
│ ./task --force generate-refschema │ 0    │ clean, output visible          │
├───────────────────────────────────┼──────┼────────────────────────────────┤
│ task ... && git diff --exit-code  │ 0    │ CI pattern works               │
└───────────────────────────────────┴──────┴────────────────────────────────┘

Co-authored-by: Isaac

The acceptance harness exited non-zero whenever `-update` applied a
change: doComparison called AssertEqualTexts (which flags the test
failed) and only overwrote the golden file afterwards. Since the test
flag, not the write, drives the exit code, every regenerated file made
`go test ... -update` exit 1 even though the update succeeded.

Regenerating outputs is the goal of -update, not a failure. Move the
OverwriteMode write/remove handling into an early-return block so a
successful update returns without marking the test failed; only genuine
problems still fail (read errors via tryReading, write errors via
require/testutil, and the "both files missing" case). The non-update
comparison path is unchanged.

This lets generate-refschema drop its `ignore_error: true` workaround
(and the `&> /dev/null` redirect that hid genuine errors), and makes
test-update / test-update-templates / test-update-aws exit 0 on changes
as intended.

Co-authored-by: Isaac
// The test no longer produces this output; drop the stale reference.
t.Logf("Removing output file: %s", relPath)
require.NoError(t, os.Remove(pathRef))
case !okRef && okNew:
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.

this also handled below and produces error there


// The test did not produce an expected output file.
if okRef && !okNew {
t.Errorf("Missing output file: %s", relPath)
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.

would not removing t.Errorf be enough? (for cleaner diff)

@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

Commit: 5279b90

Run: 26890697825

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants