func TestExpireVehicles(t *testing.T) {
	fakeServer := makeFakeServer()
	muni.SetConfig(muni.TransitConfig{DefaultURL: fakeServer.URL + "/"})

	storage.RunStorageTest(t, func(db *sqlx.DB, t *testing.T) {
		err := fetchTransit([]string{"N"})
		if err != nil {
			t.Error(err)
		}
		expireOldVehicles(time.Unix(1460498787925/1000, 0).Add(time.Minute).UTC())
		v, err := storage.GetVehiclesBeforeTime(db, time.Unix(1460498787925/1000, 0).Add(time.Minute).UTC())
		if err != nil {
			t.Error(err)
		}
		if len(v) != 0 {
			t.Error("Failed to remove vehicles from DB", len(v))
		}
	})
}
Ejemplo n.º 2
0
func TestFetchTransit(t *testing.T) {
	fakeServer := makeFakeServer()
	muni.SetConfig(muni.TransitConfig{DefaultURL: fakeServer.URL + "/"})

	storage.RunStorageTest(t, func(db *sqlx.DB, t *testing.T) {
		err := fetchTransit([]string{"N"})
		if err != nil {
			t.Error(err)
		}
		v, _ := storage.GetVehiclesAfterTime(db, time.Unix(1460498787925/1000, 0).Add(time.Minute*-5))
		if len(v) == 0 {
			t.Error("Did not add any vehicles to the DB")
		}

		if len(v) == 37 {
			t.Error("Did not add all of the vehicles to the DB")
		}
	})
}