Spaces:
Sleeping
Sleeping
feat: Add Unit Testing
Browse files- .github/workflows/proxy_deployment.yaml +1 -1
- coverage.out +1 -0
- tests/utils_test.go +42 -0
.github/workflows/proxy_deployment.yaml
CHANGED
@@ -23,7 +23,7 @@ jobs:
|
|
23 |
fetch-depth: 1
|
24 |
|
25 |
- name: unit testing
|
26 |
-
run:
|
27 |
|
28 |
# TebakAja Proxy-0
|
29 |
tebakaja_proxy_space-0:
|
|
|
23 |
fetch-depth: 1
|
24 |
|
25 |
- name: unit testing
|
26 |
+
run: go test -v ./tests -coverprofile=coverage.out
|
27 |
|
28 |
# TebakAja Proxy-0
|
29 |
tebakaja_proxy_space-0:
|
coverage.out
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
mode: set
|
tests/utils_test.go
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
package tests
|
2 |
+
|
3 |
+
import (
|
4 |
+
"reflect"
|
5 |
+
"testing"
|
6 |
+
|
7 |
+
proxy "tebakaja_lb_proxy/proxy"
|
8 |
+
)
|
9 |
+
|
10 |
+
func IsStringReflect(x interface{}) bool {
|
11 |
+
return reflect.TypeOf(x).Kind() == reflect.String
|
12 |
+
}
|
13 |
+
|
14 |
+
func IsStringTypeAssertion(x interface{}) bool {
|
15 |
+
_, ok := x.(string)
|
16 |
+
return ok
|
17 |
+
}
|
18 |
+
|
19 |
+
func TestGetEndpointByRestService(t *testing.T) {
|
20 |
+
tests := []struct {
|
21 |
+
service string
|
22 |
+
want bool
|
23 |
+
}{
|
24 |
+
{"crypto", true},
|
25 |
+
{"national", true},
|
26 |
+
{"stock", true},
|
27 |
+
}
|
28 |
+
|
29 |
+
for _, tt := range tests {
|
30 |
+
t.Run(tt.service, func(t *testing.T) {
|
31 |
+
endpoint := proxy.GetEndpointByRestService(tt.service)
|
32 |
+
|
33 |
+
if got := IsStringReflect(endpoint); got != tt.want {
|
34 |
+
t.Errorf("IsStringReflect(%v) = %v, want %v", endpoint, got, tt.want)
|
35 |
+
}
|
36 |
+
|
37 |
+
if got := IsStringTypeAssertion(endpoint); got != tt.want {
|
38 |
+
t.Errorf("IsStringTypeAssertion(%v) = %v, want %v", endpoint, got, tt.want)
|
39 |
+
}
|
40 |
+
})
|
41 |
+
}
|
42 |
+
}
|