-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebsocket_test.go
51 lines (46 loc) · 1.62 KB
/
websocket_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
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT
package omlox
import (
"encoding/json"
"testing"
)
var wrapperObjJSONTestCases = []struct {
name string
wrObj WrapperObject
json []byte
}{
{
name: "subcription",
wrObj: WrapperObject{
Event: EventSubscribe,
Topic: TopicLocationUpdates,
Params: Parameters{"crs": "EPSG:4326"},
},
json: []byte(`{"event":"subscribe","topic":"location_updates","params":{"crs":"EPSG:4326"}}`),
},
{
name: "location-update",
wrObj: WrapperObject{
Event: EventMsg,
Topic: TopicLocationUpdates,
SubscriptionID: 123,
Payload: []json.RawMessage{json.RawMessage(`{"position":{"type":"Point","coordinates":[5,4]},"source":"fdb6df62-bce8-6c23-e342-80bd5c938774","provider_type":"uwb","provider_id":"77:4f:34:69:27:40","timestamp_generated":"2019-09-02T22:02:24.355Z","timestamp_sent":"2019-09-02T22:02:24.355Z"}`)},
},
json: []byte(`{"event":"message","topic":"location_updates","subscription_id":123,"payload":[{"position":{"type":"Point","coordinates":[5,4]},"source":"fdb6df62-bce8-6c23-e342-80bd5c938774","provider_type":"uwb","provider_id":"77:4f:34:69:27:40","timestamp_generated":"2019-09-02T22:02:24.355Z","timestamp_sent":"2019-09-02T22:02:24.355Z"}]}`),
},
}
func TestWrapperObjectMarshal(t *testing.T) {
for _, tc := range wrapperObjJSONTestCases {
t.Run(tc.name, func(t *testing.T) {
JSONMarshalOK(t, tc.wrObj, tc.json)
})
}
}
func TestWrapperObjectUnmarshal(t *testing.T) {
for _, tc := range wrapperObjJSONTestCases {
t.Run(tc.name, func(t *testing.T) {
JSONUnmarshalOK(t, tc.json, tc.wrObj)
})
}
}