-
Notifications
You must be signed in to change notification settings - Fork 7
/
label_test.go
66 lines (58 loc) · 1.5 KB
/
label_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
package gsclient
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
var labelTestCases = []uuidTestCase{
{
testUUID: "test",
isFailed: false,
},
{
testUUID: "",
isFailed: true,
},
}
func TestClient_GetLabelList(t *testing.T) {
server, client, mux := setupTestClient(true)
defer server.Close()
uri := apiLabelBase
mux.HandleFunc(uri, func(writer http.ResponseWriter, request *http.Request) {
assert.Equal(t, http.MethodGet, request.Method)
writer.Header().Set(requestUUIDHeader, dummyRequestUUID)
fmt.Fprintf(writer, prepareLabelListHTTPGet("test"))
})
res, err := client.GetLabelList(emptyCtx)
assert.Nil(t, err, "GetLabelList returned an error %v", err)
assert.Equal(t, 1, len(res))
assert.Equal(t, fmt.Sprintf("[%v]", getMockLabel("test")), fmt.Sprintf("%v", res))
}
func getMockLabel(label string) Label {
mock := Label{Properties: LabelProperties{
Label: label,
CreateTime: dummyTime,
ChangeTime: dummyTime,
Relations: nil,
Status: "active",
}}
return mock
}
func getMockLabelCreateResponse() CreateResponse {
mock := CreateResponse{
RequestUUID: dummyRequestUUID,
}
return mock
}
func prepareLabelListHTTPGet(labelName string) string {
label := getMockLabel(labelName)
res, _ := json.Marshal(label.Properties)
return fmt.Sprintf(`{"labels": {"%s": %s}}`, dummyUUID, string(res))
}
func prepareLabelCreateResponse() string {
response := getMockLabelCreateResponse()
res, _ := json.Marshal(response)
return string(res)
}