-
Notifications
You must be signed in to change notification settings - Fork 7
/
testcommon.go
61 lines (51 loc) · 1.24 KB
/
testcommon.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
package gsclient
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"time"
)
const (
dummyUUID = "690de890-13c0-4e76-8a01-e10ba8786e53"
dummyRequestUUID = "690de890-13c0-4e76-8a01-e10ba8786e53"
)
var emptyCtx = context.Background()
var dummyTimeOriginal, _ = time.Parse(gsTimeLayout, "2018-04-28T09:47:41Z")
var dummyTime = GSTime{dummyTimeOriginal}
type uuidTestCase struct {
isFailed bool
testUUID string
}
type successFailTestCase struct {
isFailed bool
}
var commonSuccessFailTestCases []successFailTestCase = []successFailTestCase{
{
isFailed: true,
},
{
isFailed: false,
},
}
var uuidCommonTestCases []uuidTestCase = []uuidTestCase{
{
testUUID: dummyUUID,
isFailed: false,
},
{
testUUID: "",
isFailed: true,
},
}
var syncClientTestCases []bool = []bool{true, false}
func setupTestClient(sync bool) (*httptest.Server, *Client, *http.ServeMux) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
config := NewConfiguration(server.URL, "uuid", "token", true, sync, 100, 5)
httpResponse := fmt.Sprintf(`{"%s": {"status":"done"}}`, dummyRequestUUID)
mux.HandleFunc(requestBase, func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, httpResponse)
})
return server, NewClient(config), mux
}