event_test.go 855 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package borealis
  2. import (
  3. "encoding/json"
  4. "reflect"
  5. "testing"
  6. )
  7. var event = Event{
  8. Type: 1,
  9. TimestampS: 2,
  10. TimestampMS: 3,
  11. SequentialID: 4,
  12. UniqueID: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF},
  13. Payload: map[string]interface{}{},
  14. }
  15. var eventJSON = "[1,2,3,4,\"AAECAwQFBgcICQoLDA0ODw==\",{}]"
  16. func TestEncodeEvent(t *testing.T) {
  17. output, err := json.Marshal(event)
  18. if err != nil {
  19. t.Error(err)
  20. }
  21. actual := string(output)
  22. expected := eventJSON
  23. if actual != expected {
  24. t.Errorf("expected %v, but got %v", expected, actual)
  25. }
  26. }
  27. func TestDecodeEvent(t *testing.T) {
  28. var actual Event
  29. if err := json.Unmarshal([]byte(eventJSON), &actual); err != nil {
  30. t.Error(err)
  31. }
  32. expected := event
  33. if !reflect.DeepEqual(actual, expected) {
  34. t.Errorf("expected %v, but got %v", expected, actual)
  35. }
  36. }