Add depot, attendant, jetfire, optimus, ota services with kustomize overlays

This commit is contained in:
Chris Rai
2026-01-31 15:35:07 -05:00
parent a0ec642ca1
commit 9a5cb2f547
404 changed files with 38817 additions and 16 deletions

View File

@@ -0,0 +1,138 @@
package handlers_test
import (
"net/http"
"otaupdate/handlers"
"otaupdate/services"
"testing"
"github.com/fiskerinc/cloud-services/pkg/common"
mo "github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
"github.com/fiskerinc/cloud-services/pkg/httpclient/tester"
"github.com/fiskerinc/cloud-services/pkg/redis"
r "github.com/fiskerinc/cloud-services/pkg/redis"
rm "github.com/fiskerinc/cloud-services/pkg/redis/tester"
"github.com/fiskerinc/cloud-services/pkg/testhelper"
"github.com/fiskerinc/cloud-services/pkg/testrunner"
"github.com/go-pg/pg/v10"
)
func TestCarUpdateCancel(t *testing.T) {
r.MockRedisConnection()
mockRedis := rm.MockRedis{
GetSetResults: "[]",
}
services.SetRedisClientPool(rm.NewMockClientPool(&mockRedis))
mock := mo.MockCarUpdates{}
services.GetDB().SetCarUpdates(&mock)
vin := "1G1FP87S3GN100062"
mockCarUpdate := common.CarUpdate{
ID: 1000,
VIN: vin,
UpdateManifestID: 10,
}
trexKey := common.TRex.Key(vin)
hmiKey := common.HMI.Key(vin)
tests := []testrunner.TestCase{
{
Name: "invalid update id",
HttpTestCase: &tester.HttpTestCase{
Request: testhelper.MakeTestRequest(http.MethodDelete, "http://example.com/carupdate/1000/cancel", nil),
ExpectedStatus: http.StatusNotFound,
ExpectedResponse: `{"message":"pg: no rows in result set","error":"Not Found"}`,
},
DBTestCase: &mo.DBTestCase{
MockError: pg.ErrNoRows,
},
RedisTestCase: &rm.RedisTestCase{},
},
{
Name: "non-numeric update id",
HttpTestCase: &tester.HttpTestCase{
Request: testhelper.MakeTestRequest(http.MethodDelete, "http://example.com/carupdate/xxxx/cancel", nil),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"strconv.ParseInt: parsing \"xxxx\": invalid syntax","error":"Bad Request"}`,
},
DBTestCase: &mo.DBTestCase{},
RedisTestCase: &rm.RedisTestCase{},
},
{
Name: "database error",
HttpTestCase: &tester.HttpTestCase{
Request: testhelper.MakeTestRequest(http.MethodDelete, "http://example.com/carupdate/1000/cancel", nil),
ExpectedStatus: http.StatusServiceUnavailable,
ExpectedResponse: `{"message":"some err","error":"Service Unavailable"}`,
},
DBTestCase: &mo.DBTestCase{
MockError: someErr,
},
},
{
Name: "redis error",
HttpTestCase: &tester.HttpTestCase{
Request: testhelper.MakeTestRequest(http.MethodDelete, "http://example.com/carupdate/1000/cancel", nil),
ExpectedStatus: http.StatusServiceUnavailable,
ExpectedResponse: `{"message":"some err","error":"Service Unavailable"}`,
},
DBTestCase: &mo.DBTestCase{
MockLoadResponse: &mockCarUpdate,
},
RedisTestCase: &rm.RedisTestCase{
MockRedisError: someErr,
},
},
{
Name: "good request",
HttpTestCase: &tester.HttpTestCase{
Request: testhelper.MakeTestRequest(http.MethodDelete, "http://example.com/carupdate/1000/cancel", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"message":"OK"}`,
},
DBTestCase: &mo.DBTestCase{
MockLoadResponse: &mockCarUpdate,
},
RedisTestCase: &rm.RedisTestCase{
ExpectedMessages: map[string]string{
trexKey: `{"handler":"update_manifest_cancel","data":{"car_update_id":1000}}`,
hmiKey: `{"handler":"update_manifest_cancel","data":{"car_update_id":1000}}`,
},
ExpectedCaches: map[string]rm.ExpiringCacheResult{
redis.CarUpdateStatusHashKey(int64(1000)): {
Value: `{"current_size":0,"ecu":"","errorcode":0,"file_size":0,"file_total":0,"id":1000,"installed":0,"status":"manifest_cancel_pending","total_files":0,"total_size":0}`,
Expires: 3600,
},
},
},
},
}
schemaTesterTRex := testhelper.NewSchemaTestHelper(t, schemaToTRex)
for _, test := range tests {
mockRedis.Reset()
if test.RedisTestCase != nil {
test.RedisTestCase.SetupRedis(&mockRedis)
}
if test.DBTestCase != nil {
test.DBTestCase.SetupDB(&mock)
}
if test.HttpTestCase != nil {
w := test.HttpTestCase.TestWithParamPath(handlers.HandleCarUpdateCancel, "/carupdate/:id/cancel")
test.HttpTestCase.ValidateHttp(t, test.Name, w)
}
if test.DBTestCase != nil {
test.DBTestCase.Validate(t, test.Name, &mock)
}
if test.RedisTestCase != nil {
test.RedisTestCase.Validate(t, test.Name, &mockRedis)
for _, mes := range test.RedisTestCase.ExpectedMessages {
schemaTesterTRex.ValidateSchemaObject(test.Name, []byte(mes))
}
}
}
}