package borealis import ( "bytes" "encoding/json" "testing" "github.com/fxamacker/cbor/v2" ) 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==\",{}]" var eventCBOR = []byte{0x86, 1, 2, 3, 4, 0x50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0xa0} func TestEncodeEventJSON(t *testing.T) { output, err := json.Marshal(event) if err != nil { t.Error(err) } actual := string(output) if actual != eventJSON { t.Errorf("expected %v, but got %v", eventJSON, actual) } } func TestEncodeEventCBOR(t *testing.T) { actual, err := cbor.Marshal(event) if err != nil { t.Error(err) } if !bytes.Equal(actual, eventCBOR) { t.Errorf("expected %v, but got %v", eventCBOR, actual) } } func TestDecodeEventJSON(t *testing.T) { var actual Event if err := json.Unmarshal([]byte(eventJSON), &actual); err != nil { t.Error(err) } if !event.Equal(actual) { t.Errorf("expected %v, but got %v", event, actual) } } func TestDecodeEventCBOR(t *testing.T) { var actual Event if err := cbor.Unmarshal([]byte(eventCBOR), &actual); err != nil { t.Error(err) } if !event.Equal(actual) { t.Errorf("expected %v, but got %v", event, actual) } }