예제 #1
0
func TestPostgresStorageInsertWithComplexJson(t *testing.T) {
	db, _ := NewPostgresStorage()
	event := histri.NewEvent(
		"type",
		"abc123",
		map[string]interface{}{
			"aaa": 9379534.84933,
			"bbb": false,
			"ccc": map[string]interface{}{
				"c_ddd": 123,
				"c_eee": []interface{}{"a", 123, true},
				"c_fff": []int64{389202384, 19890345, 8479893, -397234},
			},
			"ddd": struct {
				n int
				v string
			}{65, "abc123"},
		},
		nil,
	)
	err := db.Insert(event)
	if err != nil {
		t.Errorf("Could not Insert with complex json. Error: %q", err.Error())
	}
}
예제 #2
0
func TestPostgresStorageGetById(t *testing.T) {
	db, _ := NewPostgresStorage()
	event := histri.NewEvent(
		"type",
		"abc123",
		map[string]interface{}{
			"a": 1,
			"b": 2,
		},
		nil,
	)
	db.Insert(event)
	db, _ = NewPostgresStorage()
	eventRetrieved, err := db.ById(event.Id)
	if err != nil {
		t.Errorf("Could not get ById. Error: %q", err)
	}
	if eventRetrieved.EventType != "type" {
		t.Error("EventType was different after retrieved from DB.")
	}
	if eventRetrieved.TimeUtc.Second() != event.TimeUtc.Second() {
		t.Errorf("TimeUtc was different after retrieved from DB. %q != %q",
			eventRetrieved.TimeUtc,
			event.TimeUtc)
	}
}
예제 #3
0
func TestPostresStorageInsert(t *testing.T) {
	db, err := NewPostgresStorage()
	if err != nil {
		t.Errorf("Failed to create new PostgresStorage. Error: %q", err.Error())
	}
	event1 := histri.NewEvent(
		"type",
		"abc123",
		map[string]interface{}{
			"a": 1,
			"b": 2,
		},
		nil,
	)
	event2 := histri.NewEvent(
		"type2",
		"abc123",
		map[string]interface{}{
			"a": 1,
			"c": 3,
		},
		nil,
	)
	event3 := histri.NewEvent(
		"type",
		"abc124",
		map[string]interface{}{
			"a": 1,
			"b": 2,
		},
		nil,
	)
	oldCount, err := db.Count()
	if err != nil {
		t.Errorf("Could not get Count. Error: %q", err.Error())
	}
	err = db.Insert(event1)
	if err != nil {
		t.Errorf("Could not Insert. Error: %q", err.Error())
	}
	db.Insert(event2)
	db.Insert(event3)

	if c, _ := db.Count(); c != oldCount+3 {
		t.Error("Count does not correctly reflect new Inserts.")
	}
}
예제 #4
0
func TestStorageInsertMultiple(t *testing.T) {
	event1 := histri.NewEvent(
		"type",
		"abc123",
		map[string]interface{}{
			"a": 1,
			"b": 2,
		},
		nil,
	)
	event2 := histri.NewEvent(
		"type2",
		"abc123",
		map[string]interface{}{
			"a": 1,
			"c": 3,
		},
		nil,
	)
	event3 := histri.NewEvent(
		"type",
		"abc124",
		map[string]interface{}{
			"a": 1,
			"b": 2,
		},
		nil,
	)
	oldCount, _ := TStorage.Count()
	TStorage.Insert(event1)
	TStorage.Insert(event2)
	TStorage.Insert(event3)

	if c, _ := TStorage.Count(); c != oldCount+3 {
		t.Error("Count does not correctly reflect new Inserts.")
	}
}
예제 #5
0
func TestStorageInsertSetsNewId(t *testing.T) {
	event := histri.NewEvent(
		"type",
		"abc123",
		map[string]interface{}{
			"a": 1,
			"b": 2,
		},
		nil,
	)
	oldId := event.Id
	TStorage.Insert(event)
	if event.Id == oldId {
		t.Error("New Id was not set on Insert")
	}
}