Files

51 lines
1.4 KiB
Go

package handlers_test
import (
"net/http"
"testing"
"otaupdate/handlers"
"otaupdate/services"
"github.com/fiskerinc/cloud-services/pkg/common"
"github.com/fiskerinc/cloud-services/pkg/mongo"
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
"github.com/fiskerinc/cloud-services/pkg/utils/elptr"
)
func TestFleetGet(t *testing.T) {
client, err := services.GetMongoClient()
if err != nil {
t.Error(err)
return
}
mockMongo := mongo.NewFleetsCollection(
&mongo.MockCollection{
AggregateObject: []mongo.Fleet{
{
Name: "TESTFLEET",
CANBus: common.CANBus{DTCEnabled: elptr.ElPtr(true)},
},
},
},
)
client.SetFleets(mockMongo)
tests := []th.BasicHttpTest{
{
Name: "Valid data",
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/fleet/INVALIDFLEET$", nil),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"fleet fleet ","error":"Bad Request"}`,
},
{
Name: "Valid data",
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/fleet/TESTFLEET", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"name":"","log_level":"trace","canbus":{"enabled":false,"data_logger_enabled":false,"dtc_enabled":null},"idps_enabled":false,"tags":null,"vehicles":null,"vehicles_count":0}`,
},
}
th.RunParamHttpTests(t, tests, handlers.HandleFleetGet, "/fleet/:name")
}