container/path: use syscall dispatcher
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m8s
Test / Hakurei (push) Successful in 3m14s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m26s
Test / Hakurei (race detector) (push) Successful in 43s
Test / Flake checks (push) Successful in 1m39s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m8s
Test / Hakurei (push) Successful in 3m14s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m26s
Test / Hakurei (race detector) (push) Successful in 43s
Test / Flake checks (push) Successful in 1m39s
This allows path and mount functions to be instrumented. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -4,12 +4,14 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -101,6 +103,27 @@ func checkOpMeta(t *testing.T, testCases []opMetaTestCase) {
|
||||
})
|
||||
}
|
||||
|
||||
type simpleTestCase struct {
|
||||
name string
|
||||
f func(k syscallDispatcher) error
|
||||
want []kexpect
|
||||
wantErr error
|
||||
}
|
||||
|
||||
func checkSimple(t *testing.T, fname string, testCases []simpleTestCase) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
k := &kstub{t: t, want: tc.want}
|
||||
if err := tc.f(k); !errors.Is(err, tc.wantErr) {
|
||||
t.Errorf("%s: error = %v, want %v", fname, err, tc.wantErr)
|
||||
}
|
||||
if len(k.want) != k.pos {
|
||||
t.Errorf("%s: %d calls, want %d", fname, k.pos, len(k.want))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type opBehaviourTestCase struct {
|
||||
name string
|
||||
params *Params
|
||||
@@ -173,6 +196,24 @@ func (f *checkedOsFile) Close() error {
|
||||
return f.closeErr
|
||||
}
|
||||
|
||||
func newConstFile(s string) osFile { return &readerOsFile{Reader: strings.NewReader(s)} }
|
||||
|
||||
type readerOsFile struct {
|
||||
closed bool
|
||||
io.Reader
|
||||
}
|
||||
|
||||
func (*readerOsFile) Name() string { panic("unreachable") }
|
||||
func (*readerOsFile) Write([]byte) (int, error) { panic("unreachable") }
|
||||
func (*readerOsFile) Stat() (fs.FileInfo, error) { panic("unreachable") }
|
||||
func (r *readerOsFile) Close() error {
|
||||
if r.closed {
|
||||
return os.ErrClosed
|
||||
}
|
||||
r.closed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
type writeErrOsFile struct{ err error }
|
||||
|
||||
func (writeErrOsFile) Name() string { panic("unreachable") }
|
||||
@@ -437,6 +478,12 @@ func (k *kstub) readdir(name string) ([]os.DirEntry, error) {
|
||||
checkArg(k, "name", name, 0))
|
||||
}
|
||||
|
||||
func (k *kstub) openNew(name string) (osFile, error) {
|
||||
expect := k.expect("openNew")
|
||||
return expect.ret.(osFile), expect.error(
|
||||
checkArg(k, "name", name, 0))
|
||||
}
|
||||
|
||||
func (k *kstub) writeFile(name string, data []byte, perm os.FileMode) error {
|
||||
return k.expect("writeFile").error(
|
||||
checkArg(k, "name", name, 0),
|
||||
|
||||
Reference in New Issue
Block a user