本文整理汇总了Golang中github.com/robertreppel/hist.Eventstore.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Eventstore.Get方法的具体用法?Golang Eventstore.Get怎么用?Golang Eventstore.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/robertreppel/hist.Eventstore
的用法示例。
在下文中一共展示了Eventstore.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGettingMoreThanOneEvent
func TestGettingMoreThanOneEvent(t *testing.T) {
Convey("Given an event store", t, func() {
dataStoreDirectory := "/tmp/hist-filestore-test-data"
var eventStore hist.Eventstore
var err error
eventStore, err = FileStore(dataStoreDirectory)
if err != nil {
panic(err)
}
Convey("and three events", func() {
expectedAggregateType := "TestGetMoreThanOneEventAggregate"
id, _ := uuid.NewV4()
aggregateID := id.String()
data := []byte("{\"ShipID\":\"Seagull\",\"Location\":\"At Sea\"}")
eventStore.Save(expectedAggregateType, aggregateID, "EventType", data)
data = []byte("Second \n event.")
eventStore.Save(expectedAggregateType, aggregateID, "EventType", data)
data = []byte("Third event.")
eventStore.Save(expectedAggregateType, aggregateID, "EventType", data)
Convey("when get events is called", func() {
Convey("then an aggregate with three events is returned.", func() {
events, err := eventStore.Get(expectedAggregateType, aggregateID)
if err != nil {
panic(err)
}
So(len(events), ShouldEqual, 3)
})
})
})
})
}
示例2: TestStoringNewEvent
func TestStoringNewEvent(t *testing.T) {
Convey("Given an event store", t, func() {
dataStoreDirectory := "/tmp/hist-test-filestore-data"
var eventStore hist.Eventstore
var err error
eventStore, err = FileStore(dataStoreDirectory)
if err != nil {
panic(err)
}
Convey("and an event which doesn't exist yet", func() {
aggregateType := "TestSaveEventAggregate"
id, _ := uuid.NewV4()
aggregateID := id.String()
data := []byte("Here's a test event.")
Convey("when save event is called", func() {
eventStore.Save(aggregateType, aggregateID, "EventType", data)
Convey("then an aggregate with the event exists.", func() {
events, err := eventStore.Get(aggregateType, aggregateID)
if err != nil {
panic(err)
}
So(len(events) > 0, ShouldBeTrue)
})
})
})
})
}
示例3: TestMissingDataDirectory
func TestMissingDataDirectory(t *testing.T) {
Convey("Given an event store", t, func() {
dataStoreDirectory := "/tmp/hist-filestore-test-missing-datadirectory"
var store hist.Eventstore
var err error
store, err = FileStore(dataStoreDirectory)
if err != nil {
panic(err)
}
deleteAllData(dataStoreDirectory)
Convey("when I get an aggregate which doesn't exist", func() {
_, err := store.Get("UnknownAggregate", "12345")
Convey("an error should occur.", func() {
So(err.Error(), ShouldEqual, "Missing data directory")
})
})
})
}
示例4: TestGettingAggregateWhichDoesntExist
func TestGettingAggregateWhichDoesntExist(t *testing.T) {
Convey("Given an event store", t, func() {
dataStoreDirectory := "/tmp/hist-filestore-test-data"
var store hist.Eventstore
var err error
store, err = FileStore(dataStoreDirectory)
if err != nil {
panic(err)
}
Convey("when I get an aggregate which doesn't exist", func() {
events, err := store.Get("UnknownAggregate", "12345")
if err != nil {
panic(err)
}
Convey("the returned list of events should be empty.", func() {
So(events, ShouldBeEmpty)
})
})
})
}
示例5: getPortsOfCallHistory
func getPortsOfCallHistory(shipName string) []interface{} {
var store hist.Eventstore
var err error
if useDynamo {
store, err = dynamostore.DynamoStore(eventstoreTable, region, endpoint)
failIf(err)
} else {
store, err = filestore.FileStore(dataStoreDirectory)
failIf(err)
}
eventHistory, err := store.Get(shipAggregateType, shipName)
failIf(err)
var events []interface{}
for _, item := range eventHistory {
if item.Type == "ship.Registered" {
var event ship.Registered
err := json.Unmarshal(item.Data, &event)
failIf(err)
events = append(events, event)
}
if item.Type == "ship.Arrived" {
var event ship.Arrived
err := json.Unmarshal(item.Data, &event)
failIf(err)
events = append(events, event)
}
if item.Type == "ship.Departed" {
var event ship.Departed
err := json.Unmarshal(item.Data, &event)
failIf(err)
events = append(events, event)
}
}
return events
}
示例6: TestGettingOneEvent
func TestGettingOneEvent(t *testing.T) {
Convey("Given an event store", t, func() {
dataStoreDirectory := "/tmp/hist-test-filestore-data"
var eventStore hist.Eventstore
var err error
eventStore, err = FileStore(dataStoreDirectory)
if err != nil {
panic(err)
}
Convey("and an event", func() {
expectedAggregateType := "TestGetEventAggregate"
expectedEventType := "EventType"
expectedEventData := "An event to get."
id, _ := uuid.NewV4()
aggregateID := id.String()
data := []byte(expectedEventData)
eventStore.Save(expectedAggregateType, aggregateID, expectedEventType, data)
Convey("when get events is called", func() {
Convey("then an aggregate with the event is returned.", func() {
events, err := eventStore.Get(expectedAggregateType, aggregateID)
if err != nil {
panic(err)
}
So(len(events), ShouldEqual, 1)
event := events[0]
Convey("and the type of the event is correct.", func() {
So(event.Type, ShouldEqual, expectedEventType)
})
Convey("and the event data returned are correct.", func() {
So(string(event.Data), ShouldEqual, expectedEventData)
})
})
})
})
})
}