Skip to content

Commit

Permalink
test(internal/elfreader): add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <[email protected]>
  • Loading branch information
alegrey91 committed Jan 27, 2025
1 parent 03d6562 commit 4e7d728
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions internal/elfreader/symbols_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package elfreader

import (
"testing"
)

func Test_isGoroutine(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "is not goroutine",
args: args{
s: "github.com/alegrey91/harpoon/internal/archiver.Convert",
},
want: false,
},
{
name: "is goroutine",
args: args{
s: "debug/dwarf.(*Data).readType.func1",
},
want: true,
},
{
name: "is goroutine",
args: args{
s: "debug/dwarf.(*Data).readType.func2",
},
want: true,
},
{
name: "is goroutine",
args: args{
s: "os.ReadDir.func1",
},
want: true,
},
{
name: "is goroutine",
args: args{
s: "github.com/myuser/myproject/pkg/api.ForbiddenListSpec.ExactMatch.SearchStrings.func2",
},
want: true,
},
{
name: "is goroutine",
args: args{
s: "github.com/prometheus/client_golang/prometheus.goRuntimeMemStats.func21",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isGoroutine(tt.args.s); got != tt.want {
t.Errorf("isGoroutine() = %v, want %v", got, tt.want)
}
})
}
}

func Test_isTestFunction(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "is test function",
args: args{
s: "github.com/myuser/myproject/api/v1beta1.TestOwnerListSpec_FindOwner",
},
want: true,
},
{
name: "is not test function",
args: args{
s: "net/http.http2got1xxFuncForTests",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isTestFunction(tt.args.s); got != tt.want {
t.Errorf("isTestFunction() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 4e7d728

Please sign in to comment.