event_test.go 590 B

123456789101112131415161718192021222324252627282930
  1. package borealis
  2. import (
  3. "encoding/json"
  4. "testing"
  5. )
  6. func TestEncodeEvent(t *testing.T) {
  7. event := Event{Type: 0x1234}
  8. output, err := json.Marshal(event)
  9. if err != nil {
  10. t.Error(err)
  11. }
  12. actual := string(output)
  13. expected := "[4660]"
  14. if actual != expected {
  15. t.Errorf("expected %v, but got %v", expected, actual)
  16. }
  17. }
  18. func TestDecodeEvent(t *testing.T) {
  19. var actual Event
  20. if err := json.Unmarshal([]byte("[4660]"), &actual); err != nil {
  21. t.Error(err)
  22. }
  23. expected := Event{Type: 0x1234}
  24. if actual != expected {
  25. t.Errorf("expected %v, but got %v", expected, actual)
  26. }
  27. }