package borealis import ( "bytes" "encoding/json" "testing" "time" "github.com/segmentio/ksuid" ) var expectedEvent = Event[string]{ Type: 1, SequentialID: 2, Timestamp: time.UnixMicro(1231006508004000), UniqueID: ksuid.KSUID{245, 237, 93, 44, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Payload: "Testing", } var expectedRawEvent = RawEvent[string]{ Version: V1MessageVersion, Envelop: Envelop{ Type: 1, SequentialID: 2, TimestampS: 3, TimestampMS: 4, UniqueID: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, }, Payload: "Testing", } var expectedRawEventJSON = "[1,1,2,3,4,\"AAECAwQFBgcICQoLDA0ODw==\",\"Testing\"]" var expectedRawEventCBOR = []byte{1, 165, 106, 101, 118, 101, 110, 116, 95, 116, 121, 112, 101, 1, 109, 115, 101, 113, 117, 101, 110, 116, 105, 97, 108, 95, 105, 100, 2, 107, 116, 105, 109, 101, 115, 116, 97, 109, 112, 95, 115, 3, 108, 116, 105, 109, 101, 115, 116, 97, 109, 112, 95, 109, 115, 4, 105, 117, 110, 105, 113, 117, 101, 95, 105, 100, 80, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 103, 84, 101, 115, 116, 105, 110, 103} func TestNewRawEvent(t *testing.T) { _, err := NewRawEvent(0x1234, make(map[string]interface{})) if err != nil { t.Error(err) } } func TestCheckEvent(t *testing.T) { actualEvent, err := expectedRawEvent.Check() if err != nil { t.Error(err) } if !expectedEvent.Equal(*actualEvent) { t.Errorf("expected %v, but got %v", expectedEvent, actualEvent) } } func TestEncodeRawEventJSON(t *testing.T) { output, err := json.Marshal(expectedRawEvent) if err != nil { t.Error(err) } actual := string(output) if actual != expectedRawEventJSON { t.Errorf("expected %v, but got %v", expectedRawEventJSON, actual) } } func TestEncodeRawEventCBOR(t *testing.T) { actual, err := expectedRawEvent.EncodeCBOR() if err != nil { t.Error(err) } if !bytes.Equal(actual, expectedRawEventCBOR) { t.Errorf("expected %v, but got %v", expectedRawEventCBOR, actual) } } func TestDecodeRawEventJSON(t *testing.T) { var actual RawEvent[string] if err := json.Unmarshal([]byte(expectedRawEventJSON), &actual); err != nil { t.Error(err) } if !expectedRawEvent.Equal(actual) { t.Errorf("expected %v, but got %v", expectedRawEvent, actual) } } func TestDecodeRawEventCBOR(t *testing.T) { var actual RawEvent[string] if err := actual.DecodeCBOR(expectedRawEventCBOR); err != nil { t.Error(err) } if !expectedRawEvent.Equal(actual) { t.Errorf("expected %v, but got %v", expectedRawEvent, actual) } }