func initRepository(t *testing.T) (repo eventRepository) {
	dbServiceURI, err := cftools.GetVCAPServiceProperty("mongo-eventrollup", "url", appEnv)
	if err != nil || len(dbServiceURI) == 0 {
		t.Errorf("\nError retreieving database configuration: %v\n", err)
	} else {
		telemetryCollection := cfmgo.Connect(cfmgo.NewCollectionDialer, dbServiceURI, "telemetry")
		positionsCollection := cfmgo.Connect(cfmgo.NewCollectionDialer, dbServiceURI, "positions")
		alertsCollection := cfmgo.Connect(cfmgo.NewCollectionDialer, dbServiceURI, "alerts")
		repo = mongo.NewEventRollupRepository(positionsCollection, alertsCollection, telemetryCollection)
	}
	return
}
Пример #2
0
func initRepository() (repo eventRepository) {
	appEnv, _ := cfenv.Current()
	dbServiceURI, err := cftools.GetVCAPServiceProperty("mongo-eventrollup", "url", appEnv)
	if err != nil || len(dbServiceURI) == 0 {
		if err != nil {
			fmt.Printf("\nError retreieving database configuration: %v\n", err)
		}
		fmt.Println("MongoDB was not detected, using fake repository (THIS IS BAD)...")
		repo = newFakeRepository()
	} else {
		telemetryCollection := cfmgo.Connect(cfmgo.NewCollectionDialer, dbServiceURI, "telemetry")
		positionsCollection := cfmgo.Connect(cfmgo.NewCollectionDialer, dbServiceURI, "positions")
		alertsCollection := cfmgo.Connect(cfmgo.NewCollectionDialer, dbServiceURI, "alerts")
		repo = mongo.NewEventRollupRepository(positionsCollection, alertsCollection, telemetryCollection)
	}
	return
}