Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
package usecase_helpers
import (
"testing"
m "fiskerinc.com/modules/common"
"fiskerinc.com/modules/db/queries"
"fiskerinc.com/modules/db/queries/mocks"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
var someErr = errors.New("some err")
func TestPopulateECUsCurrentVersion(t *testing.T) {
mockVIN := ""
tests := map[string]struct {
cars queries.CarsInterface
ecus []*m.UpdateManifestECU
expEcus []*m.UpdateManifestECU
expErr error
}{
"correct": {
cars: &mocks.MockCars{
SelectCarECUs: []m.CarECU{
{ECU: "TREX", Version: " S213C213"},
{ECU: "PKC", Version: " S213C222"},
},
},
ecus: []*m.UpdateManifestECU{
{ECU: "TREX"},
{ECU: "PKC"},
{ECU: "MPT"},
},
expEcus: []*m.UpdateManifestECU{
{ECU: "TREX", CurrentVersion: " S213C213"},
{ECU: "PKC", CurrentVersion: " S213C222"},
{ECU: "MPT"},
},
},
"empty_car_ecus": {
cars: &mocks.MockCars{},
ecus: []*m.UpdateManifestECU{
{ECU: "TREX"},
{ECU: "PKC"},
{ECU: "MPT"},
},
expEcus: []*m.UpdateManifestECU{
{ECU: "TREX"},
{ECU: "PKC"},
{ECU: "MPT"},
},
},
"get_car_ecus_error": {
cars: &mocks.MockCars{
DBMockHelper: mocks.DBMockHelper{Error: someErr},
},
ecus: []*m.UpdateManifestECU{
{ECU: "TREX"},
{ECU: "PKC"},
{ECU: "MPT"},
},
expErr: someErr,
},
}
for tname, tt := range tests {
t.Run(tname, func(t *testing.T) {
err := PopulateECUsCurrentVersion(tt.cars, mockVIN, tt.ecus)
if err != nil && tt.expErr != nil {
assert.Equal(t, tt.expErr.Error(), err.Error())
return
}
assert.Equal(t, tt.expErr, err)
assert.Equal(t, tt.expEcus, tt.ecus)
})
}
}