-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
main_test.go
76 lines (72 loc) · 1.91 KB
/
main_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
package main
import (
"os"
"testing"
)
func Test_getContributingURL(t *testing.T) {
var TestCases = []struct {
Name string
ContributingURL string
Owner string
RepositoryName string
ExpectedOuptput string
}{
{
Name: "Empty contributing URL",
ContributingURL: "",
Owner: "openfaas",
RepositoryName: "faas",
ExpectedOuptput: "https://github.com/openfaas/faas/blob/master/CONTRIBUTING.md",
},
{
Name: "Non empty contributing URL",
ContributingURL: "https://github.com/openfaas/faas/blob/master/CONTRIBUTING.md",
Owner: "openfaas",
RepositoryName: "faas",
ExpectedOuptput: "https://github.com/openfaas/faas/blob/master/CONTRIBUTING.md",
},
}
for _, test := range TestCases {
actualContrinbutingURL := getContributingURL(test.ContributingURL, test.Owner, test.RepositoryName)
if actualContrinbutingURL != test.ExpectedOuptput {
t.Errorf("Testcase %s failed. want - %s, got - %s", test.Name, test.ExpectedOuptput, actualContrinbutingURL)
}
}
}
func Test_customerValidation(t *testing.T) {
tests := []struct {
title string
value string
expectedBool bool
}{
{
title: "`validate_hmac` is unset, defaults to on",
value: "",
expectedBool: true,
},
{
title: "`validate_hmac` is set with random value, defaults to on",
value: "random",
expectedBool: true,
},
{
title: "`validate_hmac` is set with explicit `0`",
value: "0",
expectedBool: false,
},
{
title: "`validate_hmac` is set with explicit `false`",
value: "false",
expectedBool: false,
},
}
for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
os.Setenv("validate_hmac", test.value)
value := hmacValidation()
if value != test.expectedBool {
t.Errorf("Expected value: %v got: %v", test.expectedBool, value)
}
})
}
}