forked from gridscale/gsclient-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_test.go
46 lines (41 loc) · 1.17 KB
/
event_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
package gsclient
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClient_GetEventList(t *testing.T) {
server, client, mux := setupTestClient(true)
defer server.Close()
uri := apiEventBase
mux.HandleFunc(uri, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
w.Header().Set(requestUUIDHeader, dummyRequestUUID)
fmt.Fprint(w, prepareEventListHTTPGet())
})
response, err := client.GetEventList(emptyCtx)
assert.Nil(t, err, "GetEventList returned an error %v", err)
assert.Equal(t, 1, len(response))
assert.Equal(t, fmt.Sprintf("[%v]", getMockEvent()), fmt.Sprintf("%v", response))
}
func getMockEvent() Event {
mock := Event{Properties: EventProperties{
ObjectType: "type",
RequestUUID: dummyRequestUUID,
ObjectUUID: dummyUUID,
Activity: "sent",
RequestType: "type",
RequestStatus: "active",
Change: "change",
Timestamp: dummyTime,
UserUUID: dummyUUID,
}}
return mock
}
func prepareEventListHTTPGet() string {
event := getMockEvent()
res, _ := json.Marshal(event.Properties)
return fmt.Sprintf(`{"events": [%s]}`, string(res))
}