Skip to content

Commit 82c0c27

Browse files
committed
chore: trim comments
1 parent b8cad76 commit 82c0c27

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

modules/core/teststate/teststate.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
//
88
// This package lives in core rather than teststructure so that modules such as aws, k8s, packer, and ssh can provide
99
// their own helpers without teststructure having to import every one of them.
10-
// Every t.Fatalf in this package is followed by an explicit return. testing.TestingT documents FailNow as stopping
11-
// execution via runtime.Goexit, and *testing.T honours that, so those returns are unreachable in ordinary use. They
12-
// are not decorative: TestingT exists so other harnesses can be plugged in, and an implementation whose FailNow
13-
// returns would otherwise carry on past the failure. In save that meant writing a zero byte file after a marshal
14-
// error, and in IsPresent and IsEmptyJSON it meant masking the real error behind a plausible looking answer.
10+
// Every t.Fatalf here is followed by an explicit return. They are unreachable with *testing.T, whose FailNow calls
11+
// runtime.Goexit, but TestingT allows other harnesses, and one whose FailNow returns would otherwise carry on past
12+
// the failure.
1513
package teststate
1614

1715
import (

modules/core/teststate/teststate_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ func TestSaveWritesOwnerOnlyPermissions(t *testing.T) {
205205
assert.Equal(t, os.FileMode(0o600), info.Mode().Perm(), "saved test data must be owner read/write only")
206206
}
207207

208-
// nonStoppingT is a testing.TestingT whose FailNow returns instead of calling runtime.Goexit. The interface
209-
// documents Goexit semantics, but TestingT exists so other harnesses can be plugged in, and this pins that a
210-
// harness which does not stop cannot make this package do damage after it has reported a failure.
208+
// nonStoppingT is a TestingT whose FailNow returns rather than calling runtime.Goexit, so these tests can assert
209+
// that the package stops doing work after it reports a failure.
211210
type nonStoppingT struct {
212211
failed bool
213212
msgs []string
@@ -225,14 +224,13 @@ func (r *nonStoppingT) Fatalf(f string, a ...any) {
225224
r.FailNow()
226225
}
227226

228-
// unmarshalable has a func field, which encoding/json always rejects, so Save fails at the marshal step.
227+
// unmarshalable fails json.Marshal: encoding/json always rejects a func field.
229228
type unmarshalable struct {
230229
Fn func()
231230
}
232231

233-
// TestSaveWritesNothingAfterAMarshalFailure is the regression test. Before the explicit return, save reported the
234-
// marshal failure and then carried on to os.WriteFile with a nil byte slice, leaving a zero byte file that a later
235-
// stage would try to load.
232+
// Before the fix, a marshal failure was reported and os.WriteFile still ran with a nil slice, leaving a zero byte
233+
// file for a later stage to load.
236234
func TestSaveWritesNothingAfterAMarshalFailure(t *testing.T) {
237235
t.Parallel()
238236

@@ -246,12 +244,12 @@ func TestSaveWritesNothingAfterAMarshalFailure(t *testing.T) {
246244
assert.NoFileExists(t, path, "no file may be written after a marshal failure")
247245
}
248246

249-
// TestIsPresentDoesNotMaskAnUnreadableFile pins that a read failure reports the failure rather than quietly
250-
// answering "absent", which would invite a caller to overwrite state it could not read.
247+
// A read failure must be reported, not reported as "absent", which would invite a caller to overwrite state it
248+
// could not read.
251249
func TestIsPresentDoesNotMaskAnUnreadableFile(t *testing.T) {
252250
t.Parallel()
253251

254-
// A directory where a file is expected: FileExistsE succeeds, os.ReadFile then fails with EISDIR.
252+
// A directory where a file is expected: FileExistsE succeeds, os.ReadFile fails with EISDIR.
255253
folder := t.TempDir()
256254
path := teststate.FormatPath(folder, "IsADirectory.json")
257255
require.NoError(t, os.MkdirAll(path, 0o755))
@@ -265,7 +263,7 @@ func TestIsPresentDoesNotMaskAnUnreadableFile(t *testing.T) {
265263
assert.Contains(t, recorder.msgs[0], "unexpected error")
266264
}
267265

268-
// TestIsEmptyJSONReportsAParseFailure pins that invalid JSON is reported rather than being called empty.
266+
// Invalid JSON must be reported, not called empty.
269267
func TestIsEmptyJSONReportsAParseFailure(t *testing.T) {
270268
t.Parallel()
271269

0 commit comments

Comments
 (0)