events_test.go 678 B

123456789101112131415161718192021222324252627282930
  1. package events
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "time"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. type TestEvent struct {
  9. Timestamp time.Time
  10. }
  11. func TestEventCreation(t *testing.T) {
  12. Convey("Event to wire event", t, func() {
  13. e := TestEvent{
  14. Timestamp: time.Unix(1231421123, 223),
  15. }
  16. wire, _ := ToOnWriteEvent(e)
  17. So(e.Timestamp.Unix(), ShouldEqual, wire.Timestamp.Unix())
  18. So(wire.EventType, ShouldEqual, "TestEvent")
  19. json, _ := json.Marshal(wire)
  20. So(string(json), ShouldEqual, `{"event_type":"TestEvent","priority":"INFO","timestamp":"2009-01-08T14:25:23.000000223+01:00","payload":{"Timestamp":"2009-01-08T14:25:23.000000223+01:00"}}`)
  21. })
  22. }