-
Notifications
You must be signed in to change notification settings - Fork 1
/
validation_test.go
53 lines (50 loc) · 1.14 KB
/
validation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"testing"
"github.com/brigadecore/brigade/sdk/v3"
"github.com/stretchr/testify/require"
)
func TestValidateEvent(t *testing.T) {
testCases := []struct {
name string
event sdk.Event
assertions func(error)
}{
{
name: "project not specified",
event: sdk.Event{},
assertions: func(err error) {
require.Error(t, err)
require.Contains(t, err.Error(), "project ID not specified")
require.Contains(t, err.Error(), "refusing event")
},
},
{
name: "invalid source",
event: sdk.Event{
ProjectID: "italian",
Source: "github.com/github", // Trying to emulater another source
},
assertions: func(err error) {
require.Error(t, err)
require.Contains(t, err.Error(), "source is not")
require.Contains(t, err.Error(), "refusing event")
},
},
{
name: "valid event",
event: sdk.Event{
ProjectID: "italian",
Source: source,
},
assertions: func(err error) {
require.NoError(t, err)
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
testCase.assertions(validateEvent(testCase.event))
})
}
}