Added on wire event format

This commit is contained in:
Torkel Ödegaard
2015-02-04 16:57:20 +01:00
parent dace35d31d
commit 525179eb85
5 changed files with 93 additions and 43 deletions

View File

@@ -1,18 +1,30 @@
package events
import (
"encoding/json"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
type TestEvent struct {
Timestamp time.Time
}
func TestEventCreation(t *testing.T) {
Convey("When generating slug", t, func() {
dashboard := NewDashboard("Grafana Play Home")
dashboard.UpdateSlug()
Convey("Event to wire event", t, func() {
e := TestEvent{
Timestamp: time.Unix(1231421123, 223),
}
So(dashboard.Slug, ShouldEqual, "grafana-play-home")
wire, _ := ToOnWriteEvent(e)
So(e.Timestamp.Unix(), ShouldEqual, wire.Timestamp.Unix())
So(wire.EventType, ShouldEqual, "TestEvent")
json, _ := json.Marshal(wire)
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"}}`)
})
}