forked from openfaas/openfaas-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_test.go
93 lines (90 loc) · 2.41 KB
/
handler_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package function
import (
"fmt"
"testing"
)
func Test_checkSupportedEvents(t *testing.T) {
tests := []struct {
title string
event string
expectedBool bool
}{
{
title: "Supported `push` event",
event: "push",
expectedBool: true,
},
{
title: "Supported `project_update` event",
event: "project_update",
expectedBool: true,
},
{
title: "Supported `project_destroy` event",
event: "project_destroy",
expectedBool: true,
},
{
title: "Non-supported `repository_update` event",
event: "repository_update",
expectedBool: false,
},
{
title: "Random string `random words here` event",
event: "random words here",
expectedBool: false,
},
}
for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
eventSupported := checkSupportedEvents(test.event)
if eventSupported != test.expectedBool {
t.Errorf("expected to be: %v got: %v", test.expectedBool, eventSupported)
}
})
}
}
func Test_getUser(t *testing.T) {
tests := []struct {
title string
pathWithNamespace string
expectedName string
expectedErr error
}{
{
title: "Error is nil and since the string is formated as expected",
pathWithNamespace: "exampleusername/exampleproject",
expectedName: "exampleusername",
expectedErr: nil,
},
{
title: "Error is not nil since the string is not formatted as expected",
pathWithNamespace: "exampleusername:exampleproject",
expectedName: "",
expectedErr: fmt.Errorf("un-proper format of the variable possible out of range error"),
},
{
title: "Case when field is empty",
pathWithNamespace: "",
expectedName: "",
expectedErr: fmt.Errorf("un-proper format of the variable possible out of range error"),
},
}
for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
username, userErr := getUser(test.pathWithNamespace)
if username != test.expectedName {
t.Errorf("expected name: `%s` got: `%s`", test.expectedName, username)
}
if userErr == nil {
if userErr != test.expectedErr {
t.Errorf("expected error: `%s` got: `%s`", test.expectedErr, userErr)
}
} else {
if userErr.Error() != test.expectedErr.Error() {
t.Errorf("expected error: `%s` got: `%s`", test.expectedErr, userErr)
}
}
})
}
}