Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
78
pkg/usecase_helpers/ecus_test.go
Normal file
78
pkg/usecase_helpers/ecus_test.go
Normal 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user