-
Notifications
You must be signed in to change notification settings - Fork 5
/
webhooker_test.go
57 lines (46 loc) · 1.04 KB
/
webhooker_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
54
55
56
57
// (c) 2013 Alexander Solovyov
package main
import (
"github.com/stretchr/testify/mock"
"testing"
)
type MockedRule struct {
mock.Mock
Pattern string
}
func (r *MockedRule) Match(path string) bool {
r.Mock.Called(path)
return path == r.Pattern
}
func (r *MockedRule) String() string {
return r.Pattern
}
func (r *MockedRule) Run(data Payload) (string, error) {
args := r.Mock.Called(data)
return "", args.Error(0)
}
func TestRunIsCalled(t *testing.T) {
data := &GithubPayload{
Ref: "refs/heads/main",
Repository: GithubRepo{
Name: "webhooker",
FullName: "piranha/webhooker",
},
}
wrong := &MockedRule{
Pattern: "nothing",
}
right := &MockedRule{
Pattern: "piranha/webhooker:main",
}
wrong.On("Match", GetPath(data)).Return(false)
right.On("Match", GetPath(data)).Return(true)
right.On("Run", data).Return(nil)
c := &Config{wrong, right}
_, err := c.ExecutePayload(data)
if err != nil {
t.Error("ExecutePayload should not return an error")
}
wrong.Mock.AssertExpectations(t)
right.Mock.AssertExpectations(t)
}