This repository was archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathservice_test.go
94 lines (91 loc) · 2.34 KB
/
service_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
94
package sdk
import (
"testing"
)
func Test_FormatServiceName(t *testing.T) {
values := []struct {
eventOwner string
functionName string
expectedName string
}{
{
eventOwner: "ExampleName",
functionName: "ExampleFunction",
expectedName: "examplename-ExampleFunction",
},
{
eventOwner: "examplename",
functionName: "ExampleFunction",
expectedName: "examplename-ExampleFunction",
},
{
eventOwner: "examplename",
functionName: "examplefunction",
expectedName: "examplename-examplefunction",
},
{
eventOwner: "ExampleName",
functionName: "examplefunction",
expectedName: "examplename-examplefunction",
},
}
for _, test := range values {
serviceName := FormatServiceName(test.eventOwner, test.functionName)
if serviceName != test.expectedName {
t.Errorf("Expected name: `%v` got: `%v`", test.expectedName, serviceName)
}
}
}
func Test_CreateServiceURL(t *testing.T) {
tests := []struct {
title string
URL string
suffix string
expectedURL string
}{
{
title: "URL formatted for Swarm with port",
URL: "http://gateway:8080",
suffix: "",
expectedURL: "http://gateway:8080",
},
{
title: "URL formatted for Kubernetes",
URL: "http://gateway:8080",
suffix: "openfaas",
expectedURL: "http://gateway.openfaas:8080",
},
{
title: "URL formatted for Kubernetes showing backward compatability",
URL: "http://gateway.openfaas:8080",
suffix: "openfaas",
expectedURL: "http://gateway.openfaas:8080",
},
{
title: "URL formatted for Kubernetes showing backward compatability when suffix is not present",
URL: "http://gateway.openfaas:8080",
suffix: "",
expectedURL: "http://gateway.openfaas:8080",
},
{
title: "URL formatted for Swarm without port",
URL: "http://gateway",
suffix: "",
expectedURL: "http://gateway",
},
{
title: "URL formatted for Kubernetes without port",
URL: "http://gateway",
suffix: "openfaas",
expectedURL: "http://gateway.openfaas",
},
}
for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
URL := CreateServiceURL(test.URL, test.suffix)
if URL != test.expectedURL {
t.Errorf("Expected: `%v` got: `%v`", test.expectedURL, URL)
}
})
}
}