-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdlManagement_test.go
More file actions
102 lines (80 loc) · 3.09 KB
/
IdlManagement_test.go
File metadata and controls
102 lines (80 loc) · 3.09 KB
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
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"net/http"
"testing"
"github.com/Cs1799205202/API-Gateway/biz/handler/gateway"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/test/assert"
"github.com/cloudwego/hertz/pkg/common/ut"
)
func TestGreetings(t *testing.T) {
h := server.Default()
h.GET("/agw", gateway.Greeting)
w := ut.PerformRequest(h.Engine, "GET", "/agw", nil,
ut.Header{Key: "Connection", Value: "close"})
resp := w.Result()
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "Welcome to API Gateway!", string(resp.Body()))
}
func TestListAndUpdate1(t *testing.T) {
h := server.Default()
register(h)
w := ut.PerformRequest(h.Engine, "GET", "/idl/list", nil)
resp := w.Result()
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "[]", string(resp.Body()))
w = ut.PerformRequest(h.Engine, "POST", "/idl/update/lower", nil)
resp = w.Result()
fmt.Print(string(resp.Body()))
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "idl lower.thrift found, add lower service to API gateway!", string(resp.Body()))
_, ok := gateway.ClientMap.Load("lower")
assert.Assert(t, ok)
w = ut.PerformRequest(h.Engine, "POST", "/idl/update/lower", nil)
resp = w.Result()
fmt.Print(string(resp.Body()))
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "idl lower.thrift found, idl management platform updated!", string(resp.Body()))
_, ok = gateway.ClientMap.Load("lower")
assert.Assert(t, ok)
}
func TestListAndUpdate2(t *testing.T) {
h := server.Default()
register(h)
gateway.ClientMap.Delete("lower")
gateway.ClientMap.Delete("upper")
w := ut.PerformRequest(h.Engine, "GET", "/idl/list", nil)
resp := w.Result()
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "[]", string(resp.Body()))
w = ut.PerformRequest(h.Engine, "POST", "/idl/update/upper", nil)
resp = w.Result()
fmt.Print(string(resp.Body()))
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "idl upper.thrift found, add upper service to API gateway!", string(resp.Body()))
_, ok := gateway.ClientMap.Load("upper")
assert.Assert(t, ok)
w = ut.PerformRequest(h.Engine, "POST", "/idl/update/upper", nil)
resp = w.Result()
fmt.Print(string(resp.Body()))
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "idl upper.thrift found, idl management platform updated!", string(resp.Body()))
_, ok = gateway.ClientMap.Load("upper")
assert.Assert(t, ok)
}
func TestDelete(t *testing.T) {
h := server.Default()
register(h)
gateway.ClientMap.Delete("lower")
gateway.ClientMap.Delete("upper")
w := ut.PerformRequest(h.Engine, "GET", "/idl/list", nil)
resp := w.Result()
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "[]", string(resp.Body()))
w = ut.PerformRequest(h.Engine, "POST", "/idl/update/upper", nil)
resp = w.Result()
fmt.Print(string(resp.Body()))
assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
assert.DeepEqual(t, "idl upper.thrift found, add upper service to API gateway!", string(resp.Body()))
}