|
@@ -2,17 +2,27 @@ package borealis
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "reflect"
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
+var event = Event{
|
|
|
+ Type: 1,
|
|
|
+ TimestampS: 2,
|
|
|
+ TimestampMS: 3,
|
|
|
+ SequentialID: 4,
|
|
|
+ UniqueID: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF},
|
|
|
+ Payload: map[string]interface{}{},
|
|
|
+}
|
|
|
+var eventJSON = "[1,2,3,4,\"AAECAwQFBgcICQoLDA0ODw==\",{}]"
|
|
|
+
|
|
|
func TestEncodeEvent(t *testing.T) {
|
|
|
- event := Event{Type: 0x1234}
|
|
|
output, err := json.Marshal(event)
|
|
|
if err != nil {
|
|
|
t.Error(err)
|
|
|
}
|
|
|
actual := string(output)
|
|
|
- expected := "[4660]"
|
|
|
+ expected := eventJSON
|
|
|
if actual != expected {
|
|
|
t.Errorf("expected %v, but got %v", expected, actual)
|
|
|
}
|
|
@@ -20,11 +30,11 @@ func TestEncodeEvent(t *testing.T) {
|
|
|
|
|
|
func TestDecodeEvent(t *testing.T) {
|
|
|
var actual Event
|
|
|
- if err := json.Unmarshal([]byte("[4660]"), &actual); err != nil {
|
|
|
+ if err := json.Unmarshal([]byte(eventJSON), &actual); err != nil {
|
|
|
t.Error(err)
|
|
|
}
|
|
|
- expected := Event{Type: 0x1234}
|
|
|
- if actual != expected {
|
|
|
+ expected := event
|
|
|
+ if !reflect.DeepEqual(actual, expected) {
|
|
|
t.Errorf("expected %v, but got %v", expected, actual)
|
|
|
}
|
|
|
}
|