Skip to content

Commit c5bca4e

Browse files
committed
chore: add tests
1 parent 250c5e8 commit c5bca4e

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/lmittmann/tint v1.0.5
1717
github.com/muesli/termenv v0.15.2
1818
github.com/samber/slog-multi v1.2.0
19+
github.com/stretchr/testify v1.9.0
1920
github.com/teacat/noire v1.1.0
2021
github.com/urfave/cli/v2 v2.27.4
2122
github.com/vektah/gqlparser/v2 v2.5.16
@@ -40,6 +41,7 @@ require (
4041
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
4142
github.com/mattn/go-isatty v0.0.20 // indirect
4243
github.com/mattn/go-runewidth v0.0.15 // indirect
44+
github.com/pmezard/go-difflib v1.0.0 // indirect
4345
github.com/rivo/uniseg v0.4.7 // indirect
4446
github.com/russross/blackfriday/v2 v2.1.0 // indirect
4547
github.com/samber/lo v1.38.1 // indirect
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package config_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/jippi/scm-engine/pkg/config"
7+
"github.com/jippi/scm-engine/pkg/scm"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestIgnoreActivityFrom_Matches(t *testing.T) {
12+
t.Parallel()
13+
14+
defaultActor := scm.Actor{
15+
Username: "jippi",
16+
IsBot: false,
17+
Email: scm.Ptr("jippi@scm-engine.example.com"),
18+
}
19+
20+
botActor := scm.Actor{
21+
Username: "scm-engine",
22+
IsBot: true,
23+
}
24+
25+
tests := []struct {
26+
name string
27+
actor scm.Actor
28+
fields config.IgnoreActivityFrom
29+
want bool
30+
}{
31+
{
32+
name: "empty",
33+
want: false,
34+
},
35+
{
36+
name: "default actor",
37+
actor: defaultActor,
38+
},
39+
{
40+
name: "username: matching username",
41+
actor: defaultActor,
42+
fields: config.IgnoreActivityFrom{Usernames: []string{"jippi"}},
43+
want: true,
44+
},
45+
{
46+
name: "username: partial matching",
47+
actor: defaultActor,
48+
fields: config.IgnoreActivityFrom{Usernames: []string{"jippignu"}},
49+
want: false,
50+
},
51+
{
52+
name: "bot:, actor not a bot",
53+
actor: defaultActor,
54+
fields: config.IgnoreActivityFrom{IsBot: true},
55+
want: false,
56+
},
57+
{
58+
name: "bot: ignore bot, actor is a bot",
59+
actor: botActor,
60+
fields: config.IgnoreActivityFrom{IsBot: true},
61+
want: true,
62+
},
63+
{
64+
name: "ignore email, actor without email, should not match",
65+
actor: scm.Actor{Username: "jippi"},
66+
fields: config.IgnoreActivityFrom{Emails: []string{"demo@example.com"}},
67+
want: false,
68+
},
69+
{
70+
name: "email: actor with different email, should not match",
71+
actor: defaultActor,
72+
fields: config.IgnoreActivityFrom{Emails: []string{"demo@example.com"}},
73+
want: false,
74+
},
75+
{
76+
name: "email: actor with matching email",
77+
actor: defaultActor,
78+
fields: config.IgnoreActivityFrom{Emails: []string{"jippi@scm-engine.example.com"}},
79+
want: true,
80+
},
81+
}
82+
83+
for _, tt := range tests {
84+
t.Run(tt.name, func(t *testing.T) {
85+
t.Parallel()
86+
87+
require.Equal(t, tt.want, tt.fields.Matches(tt.actor))
88+
})
89+
}
90+
}

0 commit comments

Comments
 (0)