48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package handlers_test
|
|
|
|
import (
|
|
"net/http"
|
|
"otaupdate/handlers"
|
|
"otaupdate/services"
|
|
"testing"
|
|
|
|
"github.com/fiskerinc/cloud-services/pkg/redis/tester"
|
|
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
|
|
)
|
|
|
|
func TestHandleVehiclesLocations(t *testing.T) {
|
|
conn := tester.NewRedisMock()
|
|
conn.GetObjectRawResults = map[string][]byte{
|
|
"1F15K3R45N1234567": []byte(`{"altitude":5,"longitude":10,"latitude":15}`),
|
|
}
|
|
services.SetRedisClientPool(tester.NewMockClientPool(conn))
|
|
|
|
tests := []th.BasicHttpTest{
|
|
{
|
|
Name: "Good request",
|
|
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/carslocations", nil),
|
|
ExpectedStatus: http.StatusOK,
|
|
ExpectedResponse: `{"data":[{"altitude":5,"longitude":10,"latitude":15,"heading":0,"vin":"1F15K3R45N1234567"}],"total":1}`,
|
|
},
|
|
}
|
|
|
|
th.RunBasicHttpTests(t, tests, handlers.HandleVehiclesLocations)
|
|
}
|
|
|
|
func TestHandleVehiclesLocationsEmpty(t *testing.T) {
|
|
conn := tester.NewRedisMock()
|
|
conn.GetObjectRawResults = map[string][]byte{}
|
|
services.SetRedisClientPool(tester.NewMockClientPool(conn))
|
|
|
|
tests := []th.BasicHttpTest{
|
|
{
|
|
Name: "Good request",
|
|
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/carslocations", nil),
|
|
ExpectedStatus: http.StatusOK,
|
|
ExpectedResponse: `{"data":[],"total":0}`,
|
|
},
|
|
}
|
|
|
|
th.RunBasicHttpTests(t, tests, handlers.HandleVehiclesLocations)
|
|
}
|