diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 16:33:02 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 16:33:02 +0200 |
| commit | e91e05e585940fa48767510b671ac6e9d8e4184d (patch) | |
| tree | 0c9c2d46e9fb759386ecfe47ca8faa6b5b70a47f /internal/ior_test.go | |
| parent | e2322eeb63efc492bbaf499427afd3592c4836be (diff) | |
refactor: remove dead tracepoint attach abstractions (task 383)
Diffstat (limited to 'internal/ior_test.go')
| -rw-r--r-- | internal/ior_test.go | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/internal/ior_test.go b/internal/ior_test.go deleted file mode 100644 index 43e8091..0000000 --- a/internal/ior_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package internal - -import ( - "errors" - "strings" - "testing" -) - -type fakeTracepointProgram struct { - attachCalls int - attachErr error -} - -type fakeTracepointLink struct{} - -func (fakeTracepointLink) Destroy() error { return nil } - -func (p *fakeTracepointProgram) attachTracepoint(_, _ string) (tracepointLink, error) { - p.attachCalls++ - if p.attachErr != nil { - return nil, p.attachErr - } - return fakeTracepointLink{}, nil -} - -type fakeTracepointModule struct { - getProgramCalls []string - getProgramErrs map[string]error - programs map[string]*fakeTracepointProgram -} - -func (m *fakeTracepointModule) getProgram(progName string) (tracepointProgram, error) { - m.getProgramCalls = append(m.getProgramCalls, progName) - if err, ok := m.getProgramErrs[progName]; ok { - return nil, err - } - if prog, ok := m.programs[progName]; ok { - return prog, nil - } - return nil, errors.New("missing program") -} - -func TestAttachTracepointsWithSkipsFilteredTracepoints(t *testing.T) { - module := &fakeTracepointModule{ - programs: map[string]*fakeTracepointProgram{ - "handle_sys_enter_read": {}, - "handle_sys_enter_write": {}, - }, - getProgramErrs: map[string]error{}, - } - - err := attachTracepointsWith(module, func(tracepoint string) bool { - return tracepoint == "sys_enter_read" - }, []string{"sys_enter_read", "sys_enter_write"}, false) - if err != nil { - t.Fatalf("attachTracepointsWith returned error: %v", err) - } - - if len(module.getProgramCalls) != 1 || module.getProgramCalls[0] != "handle_sys_enter_read" { - t.Fatalf("getProgram calls = %v, want only handle_sys_enter_read", module.getProgramCalls) - } - - if module.programs["handle_sys_enter_read"].attachCalls != 1 { - t.Fatalf("read attach calls = %d, want 1", module.programs["handle_sys_enter_read"].attachCalls) - } - if module.programs["handle_sys_enter_write"].attachCalls != 0 { - t.Fatalf("write attach calls = %d, want 0", module.programs["handle_sys_enter_write"].attachCalls) - } -} - -func TestAttachTracepointsWithReturnsErrorWhenProgramMissing(t *testing.T) { - module := &fakeTracepointModule{ - programs: map[string]*fakeTracepointProgram{}, - getProgramErrs: map[string]error{ - "handle_sys_enter_read": errors.New("not found"), - }, - } - - err := attachTracepointsWith(module, func(string) bool { return true }, []string{"sys_enter_read"}, false) - if err == nil { - t.Fatal("attachTracepointsWith returned nil error, want non-nil") - } - if !strings.Contains(err.Error(), "handle_sys_enter_read") { - t.Fatalf("error %q does not mention handle_sys_enter_read", err) - } -} - -func TestAttachTracepointsWithAttachFailureContinues(t *testing.T) { - module := &fakeTracepointModule{ - programs: map[string]*fakeTracepointProgram{ - "handle_sys_enter_read": {attachErr: errors.New("no tracepoint")}, - "handle_sys_enter_write": {}, - }, - getProgramErrs: map[string]error{}, - } - - err := attachTracepointsWith(module, func(string) bool { return true }, []string{"sys_enter_read", "sys_enter_write"}, false) - if err != nil { - t.Fatalf("attachTracepointsWith returned error: %v", err) - } - - if module.programs["handle_sys_enter_read"].attachCalls != 1 { - t.Fatalf("read attach calls = %d, want 1", module.programs["handle_sys_enter_read"].attachCalls) - } - if module.programs["handle_sys_enter_write"].attachCalls != 1 { - t.Fatalf("write attach calls = %d, want 1", module.programs["handle_sys_enter_write"].attachCalls) - } -} |
