|
| 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