diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-22 22:00:40 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-22 22:02:21 +0900 |
| commit | afe23600d286cf0879717cb8b55c52ef432fce7a (patch) | |
| tree | cabcc619666ba36c93a6bafc817f6f177338fa73 /container/dispatcher_test.go | |
| parent | 09d284498109b847da0da1e2c5f883268a7f2d46 (diff) | |
container/path: use syscall dispatcher
This allows path and mount functions to be instrumented.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/dispatcher_test.go')
| -rw-r--r-- | container/dispatcher_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/container/dispatcher_test.go b/container/dispatcher_test.go index e2b553f4..f01b6f39 100644 --- a/container/dispatcher_test.go +++ b/container/dispatcher_test.go @@ -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), |
