Skip to content

Commit

Permalink
tests: add TestLogFilterOutput test
Browse files Browse the repository at this point in the history
  • Loading branch information
geyslan authored and rafaeldtinoco committed Feb 20, 2023
1 parent c177c7d commit 8f83f25
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions logger_cb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package libbpfgo

import "testing"

func TestLogFilterOutput(t *testing.T) {
tests := []struct {
libbpfPrintLevel int
output string
expectedResult bool
}{
{
output: "libbpf: prog 'trace_check_map_func_compatibility': failed to create kprobe 'check_map_func_compatibility+0x0' perf event: No such file or directory\n",
expectedResult: true,
},
{
output: "libbpf: Kernel error message: Exclusivity flag on\n",
expectedResult: true,
},
{
output: "libbpf: prog 'cgroup_skb_ingress': failed to attach to cgroup 'cgroup': Invalid argument\n",
expectedResult: true,
},
{
output: "libbpf: prog 'cgroup_skb_egress': failed to attach to cgroup 'cgroup': Invalid argument\n",
expectedResult: true,
},
{
output: "This is not a log message that should be filtered\n",
expectedResult: false,
},
{
output: "libbpf: This is not a log message that should be filtered\n",
expectedResult: false,
},
}

for _, test := range tests {
result := LogFilterOutput(test.libbpfPrintLevel, test.output)
if result != test.expectedResult {
t.Errorf("For input '%s', expected %v but got %v", test.output, test.expectedResult, result)
}
}
}

0 comments on commit 8f83f25

Please sign in to comment.