forked from jenkins-x/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook_test.go
45 lines (36 loc) · 985 Bytes
/
webhook_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
package scm_test
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/jenkins-x/go-scm/scm"
"github.com/stretchr/testify/require"
)
func TestWebhookWrapper(t *testing.T) {
testCases := []struct {
name string
verify func(name string, wh *scm.WebhookWrapper)
}{
{
name: "push.json",
verify: func(name string, wh *scm.WebhookWrapper) {
require.NotNil(t, wh.PushHook, "no push hook for test %s", name)
},
},
}
dir := filepath.Join("testdata", "webhooks")
for _, tc := range testCases {
path := filepath.Join(dir, tc.name)
require.FileExists(t, path)
wh := &scm.WebhookWrapper{}
data, err := os.ReadFile(path)
require.NoError(t, err, "failed to load file %s", path)
err = json.Unmarshal(data, wh)
require.NoError(t, err, "failed to unmarshal file %s", path)
tc.verify(tc.name, wh)
hook, err := wh.ToWebhook()
require.NoError(t, err, "failed to parse hook")
require.NotNil(t, hook, "nil wehhook returned")
}
}