func TestEventStore(t *testing.T) {
	config := &EventStoreConfig{
		Table:  "eventhorizonTest-" + eh.NewUUID().String(),
		Region: "eu-west-1",
	}
	store, err := NewEventStore(config)
	if err != nil {
		t.Fatal("there should be no error:", err)
	}
	if store == nil {
		t.Fatal("there should be a store")
	}

	t.Log("creating table:", config.Table)
	if err := store.CreateTable(); err != nil {
		t.Fatal("could not create table:", err)
	}

	defer func() {
		t.Log("deleting table:", store.config.Table)
		if err := store.DeleteTable(); err != nil {
			t.Fatal("could not delete table: ", err)
		}
	}()

	// Run the actual test suite.
	testutil.EventStoreCommonTests(t, store)

}
func TestEventStore(t *testing.T) {
	// Support Wercker testing with MongoDB.
	host := os.Getenv("MONGO_PORT_27017_TCP_ADDR")
	port := os.Getenv("MONGO_PORT_27017_TCP_PORT")

	url := "localhost"
	if host != "" && port != "" {
		url = host + ":" + port
	}

	store, err := NewEventStore(url, "test")
	if err != nil {
		t.Fatal("there should be no error:", err)
	}
	if store == nil {
		t.Fatal("there should be a store")
	}

	defer store.Close()
	defer func() {
		t.Log("clearing collection")
		if err = store.Clear(); err != nil {
			t.Fatal("there should be no error:", err)
		}
	}()

	// Run the actual test suite.
	testutil.EventStoreCommonTests(t, store)
}
func TestEventStore(t *testing.T) {
	store := NewEventStore()
	if store == nil {
		t.Fatal("there should be a store")
	}

	// Run the actual test suite.
	testutil.EventStoreCommonTests(t, store)
}
func TestEventStore(t *testing.T) {
	baseStore := memory.NewEventStore()
	store := NewEventStore(baseStore)
	if store == nil {
		t.Fatal("there should be a store")
	}

	// Run the actual test suite.
	store.StartTracing()
	savedEvents := testutil.EventStoreCommonTests(t, store)
	store.StopTracing()

	trace := store.GetTrace()
	if !reflect.DeepEqual(trace, savedEvents) {
		t.Error("there should be events traced:", trace)
	}

	// And then some more tracing specific testing.

	store.ResetTrace()
	trace = store.GetTrace()
	if len(trace) != 0 {
		t.Error("there should be no events traced:", trace)
	}

	event1 := savedEvents[0]
	aggregate1events := []eh.Event{}
	for _, e := range savedEvents {
		if e.AggregateID() == event1.AggregateID() {
			aggregate1events = append(aggregate1events, e)
		}
	}

	t.Log("save event, version 7")
	err := store.Save([]eh.Event{event1}, 6)
	if err != nil {
		t.Error("there should be no error:", err)
	}
	trace = store.GetTrace()
	if len(trace) != 0 {
		t.Error("there should be no events traced:", trace)
	}
	aggregate1events = append(aggregate1events, event1)

	t.Log("load events without tracing")
	events, err := store.Load(event1.AggregateID())
	if err != nil {
		t.Error("there should be no error:", err)
	}
	if !reflect.DeepEqual(events, aggregate1events) {
		t.Error("the loaded events should be correct:", events)
	}
}