Пример #1
0
// AllVehicles returns all of the vehicles in the system
func AllVehicles(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	db, err := storage.CreateConnection()
	if err != nil {
		log.Println("Error connecting to DB in AllVehicles")
		return
	}
	defer db.Close()
	vd, err := storage.GetVehiclesAfterTime(db, time.Now().Add(time.Minute*-4))
	compacted := utils.CompactVehicles(vd)
	out, err := json.Marshal(compacted)
	if err != nil {
		log.Println(err)
	}
	fmt.Fprint(w, string(out))
}
Пример #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")
		}
	})
}