internal/pkg: verify status kind
All checks were successful
Test / Create distribution (push) Successful in 1m14s
Test / Sandbox (push) Successful in 3m0s
Test / ShareFS (push) Successful in 4m8s
Test / Hakurei (push) Successful in 4m13s
Test / Sandbox (race detector) (push) Successful in 5m47s
Test / Hakurei (race detector) (push) Successful in 6m45s
Test / Flake checks (push) Successful in 1m23s

While it is still impossible to reliably determine the expected contents of these status files, this checks their nature for expected substitution behaviour.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-13 19:27:58 +09:00
parent 67038d5af4
commit 8c2dd3e984
2 changed files with 35 additions and 2 deletions

View File

@@ -147,6 +147,7 @@ func TestExec(t *testing.T) {
t.Errorf("unexpected status:\n%s", string(faultStatus)) t.Errorf("unexpected status:\n%s", string(faultStatus))
} }
destroyStatus(t, base, 2)
testtoolDestroy(t, base, c) testtoolDestroy(t, base, c)
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},
@@ -201,6 +202,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantNet, nil}, ), ignorePathname, wantNet, nil},
}) })
destroyStatus(t, base, 2)
testtoolDestroy(t, base, c) testtoolDestroy(t, base, c)
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},
@@ -244,6 +246,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil}, ), ignorePathname, wantOffline, nil},
}) })
destroyStatus(t, base, 2)
testtoolDestroy(t, base, c) testtoolDestroy(t, base, c)
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},
@@ -290,6 +293,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil}, ), ignorePathname, wantOffline, nil},
}) })
destroyStatus(t, base, 2)
testtoolDestroy(t, base, c) testtoolDestroy(t, base, c)
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},
@@ -358,6 +362,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil}, ), ignorePathname, wantOffline, nil},
}) })
destroyStatus(t, base, 2)
testtoolDestroy(t, base, c) testtoolDestroy(t, base, c)
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},
@@ -410,6 +415,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil}, ), ignorePathname, wantOffline, nil},
}) })
destroyStatus(t, base, 2)
testtoolDestroy(t, base, c) testtoolDestroy(t, base, c)
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},
@@ -473,6 +479,8 @@ func TestExec(t *testing.T) {
"check": {Mode: 0400, Data: []byte("binfmt")}, "check": {Mode: 0400, Data: []byte("binfmt")},
}, nil}, }, nil},
}) })
destroyStatus(t, base, 2)
}, expectsFS{ }, expectsFS{
".": {Mode: fs.ModeDir | 0700}, ".": {Mode: fs.ModeDir | 0700},

View File

@@ -245,6 +245,30 @@ func newDestroyArtifactFunc(a pkg.Artifact) func(
} }
} }
// destroyStatus counts non-substitution status entries and destroys them.
func destroyStatus(t *testing.T, base *check.Absolute, n int) {
dents, err := os.ReadDir(base.Append("status").String())
if err != nil {
t.Fatal(err)
}
for _, dent := range dents {
if !dent.Type().IsRegular() {
t.Errorf("%s: %s", dent.Name(), dent.Type())
}
if err = os.Remove(base.Append(
"status",
dent.Name(),
).String()); err != nil {
t.Fatal(err)
}
}
if len(dents) != n {
t.Errorf("ReadDir: %d entries, want %d", len(dents), n)
}
}
func TestIdent(t *testing.T) { func TestIdent(t *testing.T) {
t.Parallel() t.Parallel()
@@ -489,8 +513,9 @@ func checkWithCache(t *testing.T, testCases []cacheTestCase) {
} }
} }
// destroy non-deterministic status files // destroy empty status directory
if err := os.RemoveAll(base.Append("status").String()); err != nil { if err := syscall.Rmdir(base.Append("status").String()); err != nil {
t.Error(expectsFrom(base.Append("status").String()))
t.Fatal(err) t.Fatal(err)
} }