-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package manager | ||
|
||
import "testing" | ||
|
||
func TestProbesSelectorBuilder(t *testing.T) { | ||
selectors := (NewProbesSelectorBuilder(). | ||
AllOf(ProbeSelectorLocationRoot). | ||
ProbeID("uprobe__func1"). | ||
Check failure on line 8 in selectors_test.go GitHub Actions / run tests (1.21)
|
||
ProbeID("uprobe__func2", ProbeIdAddRetprobe). | ||
BestEffort(ProbeSelectorLocationRoot). | ||
ProbeID("kprobe__func3"). | ||
ProbeID("kprobe__func4", ProbeIdAddRetprobe). | ||
OneOf(ProbeSelectorLocationNested). | ||
ProbeID("kprobe__func5"). | ||
ProbeID("kprobe__func6")).Build() | ||
|
||
if len(selectors) != 2 { | ||
t.Fatalf("expected 2 selectors, got %d", len(selectors)) | ||
} | ||
|
||
allof, ok := selectors[0].(*AllOf) | ||
if !ok { | ||
t.Fatalf("expected AllOf, got %T", selectors[0]) | ||
} | ||
|
||
// Testing with the String() method is easier than iterating, casting and comparing each elemet | ||
// and results are the same | ||
expectedString := "AllOf {UID: EBPFFuncName:uprobe__func1}, {UID: EBPFFuncName:uprobe__func2}, {UID: EBPFFuncName:uretprobe__func2}" | ||
if allof.String() != expectedString { | ||
t.Fatalf("expected: %s, got: %s", expectedString, allof.String()) | ||
} | ||
|
||
be, ok := selectors[1].(*BestEffort) | ||
if !ok { | ||
t.Fatalf("expected BestEffort, got %T", selectors[0]) | ||
} | ||
|
||
if len(be.Selectors) != 4 { | ||
t.Fatalf("expected 4 selectors, got %d", len(be.Selectors)) | ||
} | ||
|
||
oneof, ok := be.Selectors[3].(*OneOf) | ||
if !ok { | ||
t.Fatalf("expected OneOf, got %T", be.Selectors[3]) | ||
} | ||
|
||
expectedString = "OneOf {UID: EBPFFuncName:kprobe__func5}, {UID: EBPFFuncName:kprobe__func6}" | ||
if oneof.String() != expectedString { | ||
t.Fatalf("expected: %s, got: %s", expectedString, oneof.String()) | ||
} | ||
|
||
expectedString = "BestEffort {UID: EBPFFuncName:kprobe__func3}, {UID: EBPFFuncName:kprobe__func4}, {UID: EBPFFuncName:kretprobe__func4}, {UID: EBPFFuncName:kprobe__func5}, {UID: EBPFFuncName:kprobe__func6}" | ||
if be.String() != expectedString { | ||
t.Fatalf("expected: %s, got: %s", expectedString, be.String()) | ||
} | ||
} |