Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
20
pkg/db/queries/mocks/apicalls.go
Normal file
20
pkg/db/queries/mocks/apicalls.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockAPICalls struct {
|
||||
SearchMock func(filter common.APICallsSearch, paging *queries.PageQueryOptions) ([]common.APICall, int, error)
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockAPICalls) Insert(keyValue common.APICall) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockAPICalls) Search(filter common.APICallsSearch, paging *queries.PageQueryOptions) ([]common.APICall, int, error) {
|
||||
return m.SearchMock(filter, paging)
|
||||
}
|
||||
62
pkg/db/queries/mocks/apitokens.go
Normal file
62
pkg/db/queries/mocks/apitokens.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockAPITokens struct {
|
||||
ListResult []common.APIToken
|
||||
GetResult *common.APIToken
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
m.ListResult = list.([]common.APIToken)
|
||||
} else {
|
||||
m.ListResult = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) SetLoadResp(item interface{}) {
|
||||
if item != nil {
|
||||
m.GetResult = item.(*common.APIToken)
|
||||
} else {
|
||||
m.GetResult = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) Delete(token string) (orm.Result, error) {
|
||||
m.LastFilter = &common.APIToken{Token: token}
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) Insert(keyValue common.APIToken) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) Get(token string) (*common.APIToken, error) {
|
||||
m.LastFilter = &common.APIToken{Token: token}
|
||||
return m.GetResult, m.Error
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) Update(keyValue *common.APIToken) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) Select(filter *common.APIToken, paging *queries.PageQueryOptions) ([]common.APIToken, error) {
|
||||
m.LastFilter = filter
|
||||
m.LastPaging = paging
|
||||
|
||||
return m.ListResult, m.Error
|
||||
}
|
||||
|
||||
func (m *MockAPITokens) Count(apitoken *common.APIToken) (int, error) {
|
||||
if m.Error != nil {
|
||||
return 0, m.Error
|
||||
}
|
||||
|
||||
return len(m.ListResult), nil
|
||||
}
|
||||
16
pkg/db/queries/mocks/car_config_data.go
Normal file
16
pkg/db/queries/mocks/car_config_data.go
Normal file
File diff suppressed because one or more lines are too long
32
pkg/db/queries/mocks/car_versions_log.go
Normal file
32
pkg/db/queries/mocks/car_versions_log.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockCarVersionsLog struct {
|
||||
MockLogVersionChange func(log *common.CarVersionLogs) (orm.Result, error)
|
||||
MockSelectByVIN func(vin string, options *queries.PageQueryOptions) ([]common.CarVersionLogs, int, error)
|
||||
GetCarVersionsResult map[string]string
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m MockCarVersionsLog) LogVersionChange(log *common.CarVersionLogs) (orm.Result, error) {
|
||||
return m.MockLogVersionChange(log)
|
||||
}
|
||||
|
||||
func (m MockCarVersionsLog) SelectByVIN(vin string, options *queries.PageQueryOptions) ([]common.CarVersionLogs, int, error) {
|
||||
return m.MockSelectByVIN(vin, options)
|
||||
}
|
||||
|
||||
func (m MockCarVersionsLog) GetCarVersions(vin string, timestamp time.Time) (map[string]string, error) {
|
||||
if m.Error != nil {
|
||||
return nil, m.Error
|
||||
}
|
||||
|
||||
return m.GetCarVersionsResult, nil
|
||||
}
|
||||
516
pkg/db/queries/mocks/cars.go
Normal file
516
pkg/db/queries/mocks/cars.go
Normal file
@@ -0,0 +1,516 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"fiskerinc.com/modules/validator"
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
// CarUpdate query methods
|
||||
type MockCars struct {
|
||||
SelectResponse *common.Car
|
||||
SelectC2DResponse *common.CarToDriver
|
||||
SelectCarsResponse []common.Car
|
||||
SelectCarECUs []common.CarECU
|
||||
SelectCarsForDrivers []common.CarToDriver
|
||||
SelectCarsForDriver common.CarToDriver
|
||||
SelectCarSettings []common.CarSetting
|
||||
SelectCarFlashpackVersions []common.CarFlashpackVersion
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
// GetSoftwareVersion implements queries.CarsInterface.
|
||||
func (c *MockCars) GetSoftwareVersion(vin string) (result common.CarPKCOSVersion, err error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetICCIDs implements queries.CarsInterface.
|
||||
func (c *MockCars) GetICCIDs(vins []string) (iccids []string, err error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetWhiteListCars implements queries.CarsInterface.
|
||||
func (c *MockCars) GetWhiteListCars() (vins []string, err error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// BlacklistCars implements queries.CarsInterface.
|
||||
func (c *MockCars) BlacklistCars(vin []string) (err error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// WhitelistCars implements queries.CarsInterface.
|
||||
func (c *MockCars) WhitelistCars(vin []string, source string) (err error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
var _ queries.CarsInterface = &MockCars{}
|
||||
|
||||
func (c *MockCars) UpdateICCID(car *common.Car) (orm.Result, error) {
|
||||
if car.VIN == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "VIN required",
|
||||
}
|
||||
}
|
||||
|
||||
c.ORMResponse = &MockORMResults{AffectedRows: 1}
|
||||
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) UpdateSoldStatus(car *common.Car) (orm.Result, error) {
|
||||
if car.VIN == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "VIN required",
|
||||
}
|
||||
}
|
||||
|
||||
c.ORMResponse = &MockORMResults{AffectedRows: 1}
|
||||
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) SelectByID(id int64) (*common.Car, error) {
|
||||
return c.SelectResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) SelectByVIN(vin string) (*common.Car, error) {
|
||||
return c.SelectResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) Search(filter *common.CarSearch, paging *queries.PageQueryOptions) ([]common.Car, error) {
|
||||
c.LastFilter = filter
|
||||
return c.Select(&filter.Car, paging)
|
||||
}
|
||||
|
||||
func (c *MockCars) Select(filter *common.Car, paging *queries.PageQueryOptions) ([]common.Car, error) {
|
||||
c.LastPaging = paging
|
||||
|
||||
return c.SelectCarsResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) SelectOrInsert(car *common.Car) (bool, error) {
|
||||
return c.SelectOrInsertResult, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) Delete(car *common.Car) (orm.Result, error) {
|
||||
if car.VIN == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "id required",
|
||||
}
|
||||
}
|
||||
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) Update(car *common.Car) (orm.Result, error) {
|
||||
if car.VIN == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "VIN required",
|
||||
}
|
||||
}
|
||||
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) CarsByManifest(manifest common.UpdateManifest, paging *queries.PageQueryOptions) ([]common.Car, error) {
|
||||
c.LastPaging = paging
|
||||
return c.SelectCarsResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) CountCarsByManifest(manifest common.UpdateManifest) (int, error) {
|
||||
return len(c.SelectCarsResponse), c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) Insert(car *common.Car) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) Load(car *common.Car) error {
|
||||
if c.Error != nil {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *MockCars) Count(filter *common.Car) (int, error) {
|
||||
return len(c.SelectCarsResponse), c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) SearchCount(filter *common.CarSearch) (int, error) {
|
||||
return len(c.SelectCarsResponse), c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) AddDriver(car *common.Car, driver *common.Driver, role string) (*common.CarToDriver, error) {
|
||||
if c.Error != nil {
|
||||
return nil, c.Error
|
||||
}
|
||||
if c.DriverError != nil {
|
||||
return nil, c.DriverError
|
||||
}
|
||||
|
||||
return c.SelectC2DResponse, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) SelectCarToDriver(filter *common.CarToDriver) ([]common.CarToDriver, error) {
|
||||
if c.Error != nil {
|
||||
return nil, c.Error
|
||||
}
|
||||
|
||||
return c.SelectCarsForDrivers, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetDriver(id string) (common.CarToDriver, error) {
|
||||
if c.Error != nil {
|
||||
return c.SelectCarsForDriver, c.Error
|
||||
}
|
||||
|
||||
return c.SelectCarsForDriver, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetDrivers(vin string) ([]common.CarToDriver, error) {
|
||||
if c.Error != nil {
|
||||
return nil, c.Error
|
||||
}
|
||||
|
||||
return c.SelectCarsForDrivers, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) RemoveDriver(vin string, driverID string) (orm.Result, error) {
|
||||
if c.Error != nil {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
return c.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetTRexSetting(vin string) (common.TRexSetting, error) {
|
||||
tRexSetting := common.TRexSetting{}
|
||||
if c.Error != nil {
|
||||
return tRexSetting, c.Error
|
||||
}
|
||||
|
||||
return tRexSetting, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetModels() ([]string, error) {
|
||||
if c.Error != nil {
|
||||
return nil, c.Error
|
||||
}
|
||||
|
||||
return []string{"1G1FP87S3GN100062"}, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetYears() ([]int, error) {
|
||||
if c.Error != nil {
|
||||
return nil, c.Error
|
||||
}
|
||||
|
||||
return []int{3000}, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) SetSetting(setting *common.CarSetting) (orm.Result, error) {
|
||||
if c.Error != nil {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
return c.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetVehicleSpecificSettings(driver *common.CarToDriver) ([]common.CarSetting, error) {
|
||||
return c.SelectCarSettings, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) GetSettings(driver *common.CarToDriver) ([]common.CarSetting, error) {
|
||||
return []common.CarSetting{}, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) DeleteSetting(setting *common.CarSetting) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) UpdateCarECU(ecu *common.CarECU) error {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) UpdateCarECUs(ecus []common.CarECU) error {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) InsertCarECUs(ecus []common.CarECU) error {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) uniqueFilter() []common.CarECU {
|
||||
seen := make(map[string]bool)
|
||||
filteredECUs := make([]common.CarECU, 0)
|
||||
for _, ecu := range c.SelectCarECUs {
|
||||
if !seen[ecu.VIN+ecu.ECU] {
|
||||
filteredECUs = append(filteredECUs, ecu)
|
||||
seen[ecu.VIN+ecu.ECU] = true
|
||||
}
|
||||
}
|
||||
return filteredECUs
|
||||
}
|
||||
|
||||
func (c *MockCars) GetCarECUs(filter common.CarECUFilter, paging *queries.PageQueryOptions) ([]common.CarECU, error) {
|
||||
copiedList := []common.CarECU{}
|
||||
copier.CopyWithOption(&copiedList, &c.SelectCarECUs, copier.Option{DeepCopy: true})
|
||||
if filter.Search != "" {
|
||||
return []common.CarECU{copiedList[0]}, c.Error
|
||||
}
|
||||
|
||||
if filter.Unique {
|
||||
return c.uniqueFilter(), c.Error
|
||||
}
|
||||
|
||||
return copiedList, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) GetCarECUsCount(filter common.CarECUFilter) (int, error) {
|
||||
if filter.Search != "" {
|
||||
return 1, c.Error
|
||||
}
|
||||
|
||||
if filter.Unique {
|
||||
return len(c.uniqueFilter()), c.Error
|
||||
}
|
||||
|
||||
return len(c.SelectCarECUs), c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) UpdateCarFlashpackVersion(vin string, flashpack string) (orm.Result, error) {
|
||||
return c.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetFlashpackVersions(carModel string, carTrim string, carYear int, options *queries.PageQueryOptions) ([]common.CarFlashpackVersionResponse, error) {
|
||||
return []common.CarFlashpackVersionResponse{
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "43.19",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "41.14",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetFlashpackVersionsCount(carModel string, carTrim string, carYear int) (int, error) {
|
||||
return 2, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetNextFlashpackVersion(carModel string, carTrim string, flashpack string) (*common.CarFlashpackVersionResponse, error) {
|
||||
return &common.CarFlashpackVersionResponse{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "41.14",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetCarFlashpackVersionMappingsByModelTrim(carModel string, carTrim string, options *queries.PageQueryOptions) ([]common.CarFlashpackVersion, error) {
|
||||
if c.SelectCarFlashpackVersions != nil {
|
||||
return c.SelectCarFlashpackVersions, nil
|
||||
}
|
||||
|
||||
return []common.CarFlashpackVersion{
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "44.14",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion1",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "41.14",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "41.14",
|
||||
CarECUName: "ACUN",
|
||||
CarECUVersion: "ACUNVersion",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "BCM",
|
||||
CarECUVersion: "BCMVersion",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2024,
|
||||
Flashpack: "11.0",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion4",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion0",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "ACUN",
|
||||
CarECUVersion: "ACUNVersion0",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "PDI",
|
||||
CarECUVersion: "PDIVersion",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetCarFlashpackVersionMappingsByModelTrimYearFlashpack(carModel string, carTrim string, carYear int, flashpack string, options *queries.PageQueryOptions) ([]common.CarFlashpackVersion, error) {
|
||||
if c.SelectCarFlashpackVersions != nil {
|
||||
return c.SelectCarFlashpackVersions, nil
|
||||
}
|
||||
|
||||
return []common.CarFlashpackVersion{
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "44.14",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion1",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "41.14",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2024,
|
||||
Flashpack: "11.0",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion4",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "41.14",
|
||||
CarECUName: "ACUN",
|
||||
CarECUVersion: "ACUNVersion",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "BCM",
|
||||
CarECUVersion: "BCMVersion",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "ADAS",
|
||||
CarECUVersion: "ADASVersion0",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "ACUN",
|
||||
CarECUVersion: "ACUNVersion0",
|
||||
},
|
||||
{
|
||||
CarModel: "Ocean",
|
||||
CarTrim: "Base",
|
||||
CarYear: 2023,
|
||||
Flashpack: "39.14",
|
||||
CarECUName: "PDI",
|
||||
CarECUVersion: "PDIVersion",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetCarFlashpackVersionMappingsByModelTrimYearFlashpackCount(carModel string, carTrim string, carYear int, flashpack string) (int, error) {
|
||||
if c.SelectCarFlashpackVersions != nil {
|
||||
return len(c.SelectCarFlashpackVersions), nil
|
||||
}
|
||||
|
||||
return 8, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetCarECUNamesByModelTrim(carModel string, carTrim string) ([]string, error) {
|
||||
return []string{"ADAS", "ACU", "BMS"}, nil
|
||||
}
|
||||
|
||||
func (c *MockCars) AddCarFlashpackVersionMappings(carFlashpackVersions []common.CarFlashpackVersion) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *MockCars) DeleteFlashpackVersion(carModel string, carTrim string, carYear int, flashpack string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *MockCars) GetCarsForDriver(driverID string) ([]common.CarToDriver, error) {
|
||||
return c.SelectCarsForDrivers, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) UpdateBLEKey(vin string, driverid string, blekey string) (common.DriverExternal, error) {
|
||||
return common.DriverExternal{}, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) ECUUpdatedAt(ecu common.CarECU) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCars) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
c.SelectCarsResponse = list.([]common.Car)
|
||||
} else {
|
||||
c.SelectCarsResponse = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MockCars) SetLoadResp(item interface{}) {
|
||||
if item != nil {
|
||||
c.SelectResponse = item.(*common.Car)
|
||||
} else {
|
||||
c.SelectResponse = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MockCars) GetSoftwareAndPKCVersions(vins []string) (results []common.CarPKCOSVersion, err error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
179
pkg/db/queries/mocks/carupdates.go
Normal file
179
pkg/db/queries/mocks/carupdates.go
Normal file
@@ -0,0 +1,179 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"fiskerinc.com/modules/validator"
|
||||
)
|
||||
|
||||
type MockCarUpdates struct {
|
||||
SelectCarUpdateResponse *common.CarUpdate
|
||||
SelectCarUpdatesResponse []common.CarUpdate
|
||||
SelectCarUpdateStatusesResponse []common.CarUpdateStatus
|
||||
HasPendingUpdatesResponse bool
|
||||
LoadManifest *common.UpdateManifest
|
||||
PendingUpdateSameAfterSalesUsersResponse PendingUpdatesFromSameAftersaleUserResponse
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) HasPendingUpdatesFromAftersalesUser(manifestID int64, vin string) (updateID int64, pendingUpdateSameUser bool, err error) {
|
||||
return c.PendingUpdateSameAfterSalesUsersResponse.UpdateID, c.PendingUpdateSameAfterSalesUsersResponse.PendingUpdateSameUser, c.PendingUpdateSameAfterSalesUsersResponse.Err
|
||||
}
|
||||
|
||||
type PendingUpdatesFromSameAftersaleUserResponse struct {
|
||||
PendingUpdateSameUser bool
|
||||
UpdateID int64
|
||||
Err error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) SelectByID(id int64) (*common.CarUpdate, error) {
|
||||
return c.SelectCarUpdateResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) SelectByVIN(vin string) ([]common.CarUpdate, error) {
|
||||
return c.SelectCarUpdatesResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) SelectMostRecentByVINs(vins []string) ([]common.CarUpdate, error) {
|
||||
return c.SelectCarUpdatesResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) SelectByManifestID(manifest_id int64) ([]common.CarUpdate, error) {
|
||||
return c.SelectCarUpdatesResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) SelectOrInsert(update *common.CarUpdate) (bool, error) {
|
||||
update.ID++
|
||||
return c.SelectOrInsertResult, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) Select(filter *common.CarUpdate, paging *queries.PageQueryOptions) ([]common.CarUpdate, error) {
|
||||
c.LastFilter = filter
|
||||
c.LastPaging = paging
|
||||
|
||||
return c.SelectCarUpdatesResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) Delete(update *common.CarUpdate) (orm.Result, error) {
|
||||
err := validator.ValidateIDField(update.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) UpdateStatus(update *common.CarUpdate) (orm.Result, error) {
|
||||
err := validator.ValidateIDField(update.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
update.UpdatedAt = &time.Time{}
|
||||
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) Insert(update *common.CarUpdate) (orm.Result, error) {
|
||||
update.ID++
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) Load(update *common.CarUpdate) error {
|
||||
if c.Error != nil {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
if c.SelectCarUpdateResponse != nil {
|
||||
update.VIN = c.SelectCarUpdateResponse.VIN
|
||||
update.UpdateManifestID = c.SelectCarUpdateResponse.UpdateManifestID
|
||||
}
|
||||
|
||||
if c.LoadManifest == nil {
|
||||
update.UpdateManifest = &common.UpdateManifest{
|
||||
ID: update.UpdateManifestID,
|
||||
Name: "Test",
|
||||
Version: "1.2",
|
||||
ReleaseNotes: "http://releasenotes.com",
|
||||
}
|
||||
} else {
|
||||
update.UpdateManifest = c.LoadManifest
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) Count(filter *common.CarUpdate) (int, error) {
|
||||
return len(c.SelectCarUpdatesResponse), c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) GetUpdateStatuses(carupdateid int64, paging *queries.PageQueryOptions) ([]common.CarUpdateStatus, error) {
|
||||
c.LastPaging = paging
|
||||
|
||||
return c.SelectCarUpdateStatusesResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) TruncateRequirementsAwaitForUpdate(carupdateid int64) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) CountUpdateStatuses(carupdateid int64) (int, error) {
|
||||
return len(c.SelectCarUpdateStatusesResponse), c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) GetManifest(carupdateid int64) (*common.UpdateManifest, error) {
|
||||
if c.LoadManifest == nil {
|
||||
return nil, c.Error
|
||||
}
|
||||
return c.LoadManifest, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) LogStatus(update *common.CarUpdate) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) SetLoadResp(item interface{}) {
|
||||
if item == nil {
|
||||
c.SelectCarUpdateResponse = nil
|
||||
} else {
|
||||
c.SelectCarUpdateResponse = item.(*common.CarUpdate)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
c.SelectCarUpdatesResponse = list.([]common.CarUpdate)
|
||||
} else {
|
||||
c.SelectCarUpdatesResponse = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) HasPendingUpdates(manifestID int64, vin string) (bool, error) {
|
||||
return c.HasPendingUpdatesResponse, c.Error
|
||||
}
|
||||
|
||||
var lastStatus string
|
||||
|
||||
func (c *MockCarUpdates) UpdateStatusIfNotRepeat(update *common.CarUpdate) (orm.Result, error) {
|
||||
if update.Status == lastStatus {
|
||||
return nil, queries.RepeatedStatus
|
||||
}
|
||||
|
||||
lastStatus = update.Status
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) InsertAndCreateStatus(update *common.CarUpdate) (orm.Result, error) {
|
||||
update.ID++
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCarUpdates) InsertMissingFlashpack(vin string, flashpackVersion string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ queries.CarUpdatesInterface = &MockCarUpdates{}
|
||||
53
pkg/db/queries/mocks/certificates.go
Normal file
53
pkg/db/queries/mocks/certificates.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/validator"
|
||||
)
|
||||
|
||||
// CarUpdate query methods
|
||||
type MockCertificates struct {
|
||||
DBMockHelper
|
||||
MockListResponse []common.Certificate
|
||||
MockCertificate *common.Certificate
|
||||
}
|
||||
|
||||
func (c *MockCertificates) Insert(cert *common.Certificate) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCertificates) Update(cert *common.Certificate) (orm.Result, error) {
|
||||
if cert.SerialNumber == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "Serial number required",
|
||||
}
|
||||
}
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCertificates) Remove(cert *common.Certificate) (orm.Result, error) {
|
||||
if cert.SerialNumber == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "Serial number required",
|
||||
}
|
||||
}
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCertificates) SelectByCommonName(cn string) ([]common.Certificate, error) {
|
||||
return c.MockListResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCertificates) SelectBySerial(serial string) (*common.Certificate, error) {
|
||||
return c.MockCertificate, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCertificates) SelectMostRecent(cn string, certType string) (*common.Certificate, error) {
|
||||
return c.MockCertificate, c.Error
|
||||
}
|
||||
|
||||
func (c *MockCertificates) SelectMostRecents(cn string, certTypes []string) ([]common.Certificate, error) {
|
||||
return c.MockListResponse, c.Error
|
||||
}
|
||||
78
pkg/db/queries/mocks/dbhttptest.go
Normal file
78
pkg/db/queries/mocks/dbhttptest.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
th "fiskerinc.com/modules/testhelper"
|
||||
"fiskerinc.com/modules/validator"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
const IGNORE_EXPECTED_RESP = "IGNORE_EXPECTED_RESP"
|
||||
|
||||
// Deprecated. Use modules_go/testrunner/test_case.go and modules_go/db/queries/mocks/dbtestcase.go
|
||||
type DBHttpTest struct {
|
||||
Name string
|
||||
Request *http.Request
|
||||
ExpectedStatus int
|
||||
ExpectedResponse string
|
||||
ExpectedResponseRegex *regexp.Regexp
|
||||
ValidateResponse bool `default:"false"`
|
||||
|
||||
DBTestCase
|
||||
}
|
||||
|
||||
func (test *DBHttpTest) ValidateHttp(t *testing.T, w *httptest.ResponseRecorder) {
|
||||
if test.ExpectedStatus != w.Result().StatusCode {
|
||||
th.Equal(t, fmt.Sprintf("%s status code", test.Name), test.ExpectedStatus, w.Result().StatusCode)
|
||||
}
|
||||
|
||||
if test.ExpectedResponseRegex != nil {
|
||||
if !test.ExpectedResponseRegex.Match(w.Body.Bytes()) {
|
||||
th.Equal(t, fmt.Sprintf("%s body", test.Name), test.ExpectedResponseRegex, w.Body.String())
|
||||
}
|
||||
} else if test.ExpectedResponse != IGNORE_EXPECTED_RESP && test.ExpectedResponse != w.Body.String() {
|
||||
th.Equal(t, fmt.Sprintf("%s body", test.Name), test.ExpectedResponse, w.Body.String())
|
||||
}
|
||||
|
||||
if test.ValidateResponse {
|
||||
err := validator.ValidateStruct(w.Body)
|
||||
th.NoError(t, fmt.Sprintf("%s validate body", test.Name), err)
|
||||
}
|
||||
}
|
||||
|
||||
func RunDBTests(t *testing.T, tests []DBHttpTest, handler http.HandlerFunc, mock DBMockHelperInterface) {
|
||||
for _, test := range tests {
|
||||
test.SetupDB(mock)
|
||||
|
||||
w := th.ExecHTTPHandler(handler, test.Request)
|
||||
|
||||
test.ValidateHttp(t, w)
|
||||
test.Validate(t, test.Name, mock)
|
||||
}
|
||||
}
|
||||
|
||||
func ExecHTTPRouterHandler(handler http.HandlerFunc, routePath string, request *http.Request) *httptest.ResponseRecorder {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
router := httprouter.New()
|
||||
router.HandlerFunc(request.Method, routePath, handler)
|
||||
router.ServeHTTP(recorder, request)
|
||||
|
||||
return recorder
|
||||
}
|
||||
|
||||
func RunParamHttpTests(t *testing.T, tests []DBHttpTest, handler http.HandlerFunc, routePath string, mock DBMockHelperInterface) {
|
||||
for _, test := range tests {
|
||||
test.SetupDB(mock)
|
||||
|
||||
w := ExecHTTPRouterHandler(handler, routePath, test.Request)
|
||||
|
||||
test.ValidateHttp(t, w)
|
||||
test.Validate(t, test.Name, mock)
|
||||
}
|
||||
}
|
||||
50
pkg/db/queries/mocks/dbmockhelper.go
Normal file
50
pkg/db/queries/mocks/dbmockhelper.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type DBMockHelperInterface interface {
|
||||
GetFilter() fmt.Stringer
|
||||
GetPaging() *queries.PageQueryOptions
|
||||
SetListResp(list interface{})
|
||||
SetLoadResp(item interface{})
|
||||
SetErr(error)
|
||||
SetDriverError(error)
|
||||
}
|
||||
|
||||
type DBMockHelper struct {
|
||||
SelectOrInsertResult bool
|
||||
ORMResponse orm.Result
|
||||
Error error
|
||||
DriverError error
|
||||
LastFilter fmt.Stringer
|
||||
LastPaging *queries.PageQueryOptions
|
||||
}
|
||||
|
||||
func (m *DBMockHelper) GetFilter() fmt.Stringer {
|
||||
return m.LastFilter
|
||||
}
|
||||
|
||||
func (m *DBMockHelper) GetPaging() *queries.PageQueryOptions {
|
||||
return m.LastPaging
|
||||
}
|
||||
|
||||
func (m *DBMockHelper) SetListResp(list interface{}) {
|
||||
// fmt.Printf("override SetListResp() in %s\n", reflect.TypeOf(list))
|
||||
}
|
||||
|
||||
func (m *DBMockHelper) SetLoadResp(item interface{}) {
|
||||
// fmt.Printf("override SetLoadResp() in %s\n", reflect.TypeOf(item))
|
||||
}
|
||||
|
||||
func (m *DBMockHelper) SetErr(err error) {
|
||||
m.Error = err
|
||||
}
|
||||
|
||||
func (up *DBMockHelper) SetDriverError(err error) {
|
||||
up.DriverError = err
|
||||
}
|
||||
48
pkg/db/queries/mocks/dbtestcase.go
Normal file
48
pkg/db/queries/mocks/dbtestcase.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
th "fiskerinc.com/modules/testhelper"
|
||||
)
|
||||
|
||||
type DBTestCase struct {
|
||||
ExpectedFilter fmt.Stringer
|
||||
ExpectedPage *queries.PageQueryOptions
|
||||
MockListResponse interface{}
|
||||
MockLoadResponse interface{}
|
||||
SetupMockResponse func()
|
||||
MockError error
|
||||
MockDriverError error
|
||||
}
|
||||
|
||||
func (tc *DBTestCase) SetupDB(mock DBMockHelperInterface) {
|
||||
if mock != nil {
|
||||
mock.SetErr(tc.MockError)
|
||||
mock.SetListResp(tc.MockListResponse)
|
||||
mock.SetLoadResp(tc.MockLoadResponse)
|
||||
mock.SetDriverError(tc.MockDriverError)
|
||||
}
|
||||
|
||||
if tc.SetupMockResponse != nil {
|
||||
tc.SetupMockResponse()
|
||||
}
|
||||
}
|
||||
|
||||
func (tc *DBTestCase) Validate(t *testing.T, name string, mock DBMockHelperInterface) {
|
||||
if mock != nil {
|
||||
if mock.GetFilter() != nil && tc.ExpectedFilter != nil && mock.GetFilter().String() != tc.ExpectedFilter.String() {
|
||||
t.Errorf(th.TestErrorTemplate, name, tc.ExpectedFilter.String(), mock.GetFilter().String())
|
||||
} else if mock.GetFilter() == nil && tc.ExpectedFilter != nil {
|
||||
t.Errorf(th.TestErrorTemplate, name, tc.ExpectedFilter.String(), nil)
|
||||
}
|
||||
|
||||
if mock.GetPaging() != nil && tc.ExpectedPage != nil && mock.GetPaging().String() != tc.ExpectedPage.String() {
|
||||
t.Errorf(th.TestErrorTemplate, name, tc.ExpectedPage.String(), mock.GetPaging().String())
|
||||
} else if mock.GetPaging() == nil && tc.ExpectedPage != nil {
|
||||
t.Errorf(th.TestErrorTemplate, name, tc.ExpectedPage.String(), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
54
pkg/db/queries/mocks/drivers.go
Normal file
54
pkg/db/queries/mocks/drivers.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/validator"
|
||||
)
|
||||
|
||||
// MockDrivers
|
||||
type MockDrivers struct {
|
||||
SelectResponse []common.Driver
|
||||
SelectListResponse []common.Driver
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (d *MockDrivers) Select(filter *common.Driver) ([]common.Driver, error) {
|
||||
d.LastFilter = filter
|
||||
|
||||
return d.SelectResponse, d.Error
|
||||
}
|
||||
|
||||
func (d *MockDrivers) SelectOrInsert(driver *common.Driver) (bool, error) {
|
||||
return d.SelectOrInsertResult, d.Error
|
||||
}
|
||||
|
||||
func (d *MockDrivers) Delete(driver *common.Driver) (orm.Result, error) {
|
||||
return d.ORMResponse, d.Error
|
||||
}
|
||||
|
||||
func (d *MockDrivers) Insert(driver *common.Driver) (orm.Result, error) {
|
||||
err := validator.ValidateStruct(driver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d.ORMResponse, d.Error
|
||||
}
|
||||
|
||||
func (d *MockDrivers) Load(driver *common.Driver) error {
|
||||
if d.Error != nil {
|
||||
return d.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *MockDrivers) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
d.SelectListResponse = list.([]common.Driver)
|
||||
} else {
|
||||
d.SelectListResponse = nil
|
||||
}
|
||||
}
|
||||
53
pkg/db/queries/mocks/ecckeys.go
Normal file
53
pkg/db/queries/mocks/ecckeys.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
// EccKey query methods
|
||||
type MockEccKeys struct {
|
||||
DBMockHelper
|
||||
MockListResponse []common.ECCKeys
|
||||
MockEccKeys common.ECCKeys
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) Insert(keys common.ECCKeys) (orm.Result, error) {
|
||||
return ek.ORMResponse, ek.Error
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) SelectAllPrivateKeys() ([]common.ECCKeys, error) {
|
||||
return ek.MockListResponse, ek.Error
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) SelectAllPrivateKeysByEnv(env string) ([]common.ECCKeys, error) {
|
||||
return ek.MockListResponse, ek.Error
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) SelectPublicKeysByECUByEnv(ecu string, env string) (common.ECCKeys, error) {
|
||||
return ek.MockEccKeys, ek.Error
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) SelectAllPublicKeysByEnv(env string) ([]common.ECCKeys, error) {
|
||||
return ek.MockListResponse, ek.Error
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) SelectPrivateKeysByECUsEnv(ecus []string, env string) ([]common.ECCKeys, error) {
|
||||
result := []common.ECCKeys{}
|
||||
copier.Copy(&result, &ek.MockListResponse)
|
||||
return result, ek.Error
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) SelectAllPrivateKeysByVIN(env string) ([]common.ECCKeys, error) {
|
||||
result := []common.ECCKeys{}
|
||||
copier.Copy(&result, &ek.MockListResponse)
|
||||
return result, ek.Error
|
||||
}
|
||||
|
||||
func (ek MockEccKeys) SelectAllPrivateKeysByCarUpdateID(id int64) ([]common.ECCKeys, error) {
|
||||
result := []common.ECCKeys{}
|
||||
copier.Copy(&result, &ek.MockListResponse)
|
||||
return result, ek.Error
|
||||
}
|
||||
30
pkg/db/queries/mocks/ecu_dtc.go
Normal file
30
pkg/db/queries/mocks/ecu_dtc.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockEcuDtc struct {
|
||||
DBMockHelper
|
||||
SelectDTCECUResponse []common.DTC_ECU
|
||||
LastInsertCount int
|
||||
}
|
||||
|
||||
func (c *MockEcuDtc) Insert(ecudtc *[]common.DTC_ECU) (orm.Result, error) {
|
||||
c.LastInsertCount = len(*ecudtc)
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockEcuDtc) UpdateTimestamp(dtc *common.DTC_ECU) error {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *MockEcuDtc) Select(ecudtc common.DTC_ECUQuery, paging *queries.PageQueryOptions) ([]common.DTC_ECU, error) {
|
||||
return c.SelectDTCECUResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockEcuDtc) Count(filter common.DTC_ECUQuery) (int, error) {
|
||||
return 0, c.Error
|
||||
}
|
||||
48
pkg/db/queries/mocks/filekeys.go
Normal file
48
pkg/db/queries/mocks/filekeys.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/validator"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockFileKeys struct {
|
||||
GetResponse *common.FileKey
|
||||
GetMultiResponse []common.FileKey
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (fk *MockFileKeys) Delete(fileID string) (orm.Result, error) {
|
||||
if fileID == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "FileID required",
|
||||
}
|
||||
}
|
||||
|
||||
return fk.ORMResponse, fk.Error
|
||||
}
|
||||
|
||||
func (fk *MockFileKeys) Insert(filekey common.FileKey) (orm.Result, error) {
|
||||
err := validator.ValidateStruct(filekey)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fk.ORMResponse, fk.Error
|
||||
}
|
||||
|
||||
func (fk *MockFileKeys) Get(fileID string) (*common.FileKey, error) {
|
||||
if fileID == "" {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "FileID required",
|
||||
}
|
||||
}
|
||||
|
||||
return fk.GetResponse, fk.Error
|
||||
}
|
||||
|
||||
func (fk *MockFileKeys) GetMulti(fileIDs []string) ([]common.FileKey, error) {
|
||||
return fk.GetMultiResponse, fk.Error
|
||||
}
|
||||
109
pkg/db/queries/mocks/issues.go
Normal file
109
pkg/db/queries/mocks/issues.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"fiskerinc.com/modules/validator"
|
||||
)
|
||||
|
||||
type MockIssue struct {
|
||||
SelectIssuesResponse []common.Issue
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (c *MockIssue) Insert(issue *common.Issue) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockIssue) Delete(id int) (orm.Result, error) {
|
||||
if id <= 0 {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "id cannot be less than 0",
|
||||
}
|
||||
}
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockIssue) SelectByID(id int) (*common.Issue, error) {
|
||||
if id <= 0 {
|
||||
return nil, &validator.FieldError{
|
||||
ErrorMsg: "id cannot be less than 0",
|
||||
}
|
||||
}
|
||||
|
||||
issueImage := []common.IssueImage{
|
||||
{
|
||||
ID: 1,
|
||||
Image: []byte{},
|
||||
IssueID: 1,
|
||||
},
|
||||
}
|
||||
return &common.Issue{
|
||||
ID: 1,
|
||||
VIN: "",
|
||||
Title: "",
|
||||
Description: "",
|
||||
DriverID: "",
|
||||
Timestamp: time.Time{},
|
||||
IssueImages: issueImage,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *MockIssue) Search(filter *common.IssueSearch, paging *queries.PageQueryOptions) ([]common.Issue, error) {
|
||||
if c.SelectIssuesResponse != nil {
|
||||
if filter.Search != "" && strings.Contains(c.SelectIssuesResponse[0].Title, filter.Search) {
|
||||
return []common.Issue{c.SelectIssuesResponse[0]}, nil
|
||||
}
|
||||
|
||||
return c.SelectIssuesResponse, nil
|
||||
}
|
||||
|
||||
return []common.Issue{
|
||||
{
|
||||
ID: 1,
|
||||
VIN: "",
|
||||
Title: "",
|
||||
Description: "",
|
||||
DriverID: "",
|
||||
Timestamp: time.Time{},
|
||||
IssueImages: []common.IssueImage{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *MockIssue) Count() (int, error) {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
func (c *MockIssue) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
c.SelectIssuesResponse = list.([]common.Issue)
|
||||
} else {
|
||||
c.SelectIssuesResponse = nil
|
||||
}
|
||||
}
|
||||
|
||||
type MockIssueImages struct {
|
||||
queries.QueryBase
|
||||
SearchByIssueIDResponse []common.IssueImage
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (c *MockIssueImages) Insert(issueImage *[]common.IssueImage) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockIssueImages) SearchByIssueID(issueID string) ([]common.IssueImage, error) {
|
||||
return []common.IssueImage{
|
||||
{
|
||||
ID: 1,
|
||||
Image: []byte{0, 1, 0},
|
||||
IssueID: 1,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
25
pkg/db/queries/mocks/ormresults.go
Normal file
25
pkg/db/queries/mocks/ormresults.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package mocks
|
||||
|
||||
import "github.com/go-pg/pg/v10/orm"
|
||||
|
||||
type MockORMResults struct {
|
||||
ORMModel orm.Model
|
||||
AffectedRows int
|
||||
ReturnedRows int
|
||||
}
|
||||
|
||||
func (r *MockORMResults) Model() orm.Model {
|
||||
return r.ORMModel
|
||||
}
|
||||
|
||||
func (r *MockORMResults) RowsAffected() int {
|
||||
return r.AffectedRows
|
||||
}
|
||||
|
||||
func (r *MockORMResults) RowsReturned() int {
|
||||
return r.ReturnedRows
|
||||
}
|
||||
|
||||
func (r *MockORMResults) SetModel(model orm.Model) {
|
||||
r.ORMModel = model
|
||||
}
|
||||
20
pkg/db/queries/mocks/rate_plan.go
Normal file
20
pkg/db/queries/mocks/rate_plan.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
)
|
||||
|
||||
type MockRatePlan struct {
|
||||
queries.QueryBase
|
||||
SelectResponse []common.RatePlanTMobile
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockRatePlan) Select(version string) (*common.RatePlanTMobile, error) {
|
||||
return &common.RatePlanTMobile{
|
||||
Country: "US",
|
||||
ProductID: "12345",
|
||||
PlanName: "Fisker US 5G",
|
||||
}, nil
|
||||
}
|
||||
44
pkg/db/queries/mocks/signed_images.go
Normal file
44
pkg/db/queries/mocks/signed_images.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
)
|
||||
|
||||
// EccKey query methods
|
||||
type MockSignedImages struct {
|
||||
DBMockHelper
|
||||
MockListResponse []common.SignedImage
|
||||
MockSignedImage common.SignedImage
|
||||
GetSigningCertResponse common.SupplierSigningCert
|
||||
GetSigningCertErr error
|
||||
}
|
||||
|
||||
func (si *MockSignedImages) Insert(keys common.SignedImage) (orm.Result, error) {
|
||||
return si.ORMResponse, si.Error
|
||||
}
|
||||
|
||||
func (si *MockSignedImages) SelectAll() ([]common.SignedImage, error) {
|
||||
return si.MockListResponse, si.Error
|
||||
}
|
||||
|
||||
func (si *MockSignedImages) SelectBySupplier(email string) (common.SignedImage, error) {
|
||||
return si.MockSignedImage, si.Error
|
||||
}
|
||||
|
||||
func (si *MockSignedImages) DeleteSigningCert(supplier_cert common.SupplierSigningCert) (orm.Result, error) {
|
||||
return si.ORMResponse, si.Error
|
||||
}
|
||||
|
||||
func (si *MockSignedImages) GetSigningCert(supplier string, keyCert string) (common.SupplierSigningCert, error) {
|
||||
return si.GetSigningCertResponse, si.GetSigningCertErr
|
||||
}
|
||||
|
||||
func (si *MockSignedImages) InsertSigningCert(supplier_cert common.SupplierSigningCert) (orm.Result, error) {
|
||||
return si.ORMResponse, si.Error
|
||||
}
|
||||
|
||||
func (si *MockSignedImages) SetListResp(list interface{}) {
|
||||
|
||||
}
|
||||
52
pkg/db/queries/mocks/subscription_configurations.go
Normal file
52
pkg/db/queries/mocks/subscription_configurations.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockSubscriptionConfigurations struct {
|
||||
ListResult []common.SubscriptionConfiguration
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionConfigurations) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
m.ListResult = list.([]common.SubscriptionConfiguration)
|
||||
} else {
|
||||
m.ListResult = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionConfigurations) SetLoadResp(item interface{}) {
|
||||
// no get result to set
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionConfigurations) Delete(model *common.SubscriptionConfiguration) (orm.Result, error) {
|
||||
m.LastFilter = model
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionConfigurations) Insert(model *common.SubscriptionConfiguration) (orm.Result, error) {
|
||||
m.LastFilter = model
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionConfigurations) Update(model *common.SubscriptionConfiguration) (orm.Result, error) {
|
||||
m.LastFilter = model
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionConfigurations) Count(filter *common.SubscriptionConfiguration) (int, error) {
|
||||
m.LastFilter = filter
|
||||
return len(m.ListResult), m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionConfigurations) Select(filter *common.SubscriptionConfiguration, paging *queries.PageQueryOptions) ([]common.SubscriptionConfiguration, error) {
|
||||
m.LastFilter = filter
|
||||
m.LastPaging = paging
|
||||
|
||||
return m.ListResult, m.Error
|
||||
}
|
||||
78
pkg/db/queries/mocks/subscription_features.go
Normal file
78
pkg/db/queries/mocks/subscription_features.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type MockSubscriptionFeatures struct {
|
||||
ListResult []common.SubscriptionFeature
|
||||
LoadResult *common.SubscriptionFeature
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
m.ListResult = list.([]common.SubscriptionFeature)
|
||||
} else {
|
||||
m.ListResult = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) SetLoadResp(item interface{}) {
|
||||
if item != nil {
|
||||
m.LoadResult = item.(*common.SubscriptionFeature)
|
||||
} else {
|
||||
m.LoadResult = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) Delete(model *common.SubscriptionFeature) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) Insert(model *common.SubscriptionFeature) (orm.Result, error) {
|
||||
if m.Error != nil {
|
||||
return nil, m.Error
|
||||
}
|
||||
|
||||
model.ID = uuid.MustParse("ecfb89e0-ca03-4aa9-a43a-a9d703256edb")
|
||||
|
||||
return m.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) Update(model *common.SubscriptionFeature) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) Count(filter *common.SubscriptionFeature) (int, error) {
|
||||
return len(m.ListResult), m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) Select(filter *common.SubscriptionFeature, paging *queries.PageQueryOptions) ([]common.SubscriptionFeature, error) {
|
||||
m.LastFilter = filter
|
||||
m.LastPaging = paging
|
||||
|
||||
return m.ListResult, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionFeatures) Load(model *common.SubscriptionFeature) error {
|
||||
filter := *model
|
||||
m.LastFilter = &filter
|
||||
|
||||
if m.Error != nil {
|
||||
return m.Error
|
||||
}
|
||||
|
||||
if m.LoadResult != nil {
|
||||
model.ID = m.LoadResult.ID
|
||||
model.Name = m.LoadResult.Name
|
||||
model.Description = m.LoadResult.Description
|
||||
model.Configurations = m.LoadResult.Configurations
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
98
pkg/db/queries/mocks/subscription_packages.go
Normal file
98
pkg/db/queries/mocks/subscription_packages.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type MockSubscriptionPackages struct {
|
||||
ListResult []common.SubscriptionPackage
|
||||
LoadResult *common.SubscriptionPackage
|
||||
InsertResult bool
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
result, ok := list.([]common.SubscriptionPackage)
|
||||
if ok {
|
||||
m.ListResult = result
|
||||
return
|
||||
}
|
||||
}
|
||||
m.ListResult = nil
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) SetLoadResp(item interface{}) {
|
||||
if item != nil {
|
||||
result, ok := item.(common.SubscriptionPackage)
|
||||
if ok {
|
||||
m.LoadResult = &result
|
||||
return
|
||||
}
|
||||
}
|
||||
m.LoadResult = nil
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) Delete(model *common.SubscriptionPackage) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) Insert(model *common.SubscriptionPackage) (orm.Result, error) {
|
||||
if m.Error != nil {
|
||||
return nil, m.Error
|
||||
}
|
||||
|
||||
model.ID = uuid.MustParse("0557bd1d-76d3-41e5-a44e-13c479e55ab0")
|
||||
|
||||
return m.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) Update(model *common.SubscriptionPackage) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) Count(filter *common.SubscriptionPackage) (int, error) {
|
||||
return len(m.ListResult), m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) Select(filter *common.SubscriptionPackage, paging *queries.PageQueryOptions) ([]common.SubscriptionPackage, error) {
|
||||
m.LastFilter = filter
|
||||
m.LastPaging = paging
|
||||
|
||||
return m.ListResult, m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) Load(model *common.SubscriptionPackage) error {
|
||||
filter := *model
|
||||
m.LastFilter = &filter
|
||||
|
||||
if m.LoadResult != nil {
|
||||
model.ID = m.LoadResult.ID
|
||||
model.Name = m.LoadResult.Name
|
||||
model.Features = m.LoadResult.Features
|
||||
}
|
||||
|
||||
return m.Error
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) AddFeature(pack *common.SubscriptionPackage, feature *common.SubscriptionFeature) (bool, error) {
|
||||
if m.Error != nil {
|
||||
return false, m.Error
|
||||
}
|
||||
|
||||
pack.AddFeature(feature)
|
||||
|
||||
return m.InsertResult, nil
|
||||
}
|
||||
|
||||
func (m *MockSubscriptionPackages) AssociateFeature(packageid uuid.UUID, featureid uuid.UUID) (bool, error) {
|
||||
if m.Error != nil {
|
||||
return false, m.Error
|
||||
}
|
||||
|
||||
return m.InsertResult, nil
|
||||
}
|
||||
56
pkg/db/queries/mocks/subscriptions.go
Normal file
56
pkg/db/queries/mocks/subscriptions.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockSubscriptions struct {
|
||||
ListResult []common.Subscription
|
||||
ItemResult *common.Subscription
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
// Select returns list of drivers
|
||||
func (s *MockSubscriptions) Select(filter *common.Subscription) ([]common.Subscription, error) {
|
||||
return s.ListResult, s.Error
|
||||
}
|
||||
|
||||
func (s *MockSubscriptions) Insert(subtype *common.Subscription) (orm.Result, error) {
|
||||
return s.ORMResponse, s.Error
|
||||
}
|
||||
|
||||
func (s *MockSubscriptions) Update(subtype *common.Subscription) (orm.Result, error) {
|
||||
return s.ORMResponse, s.Error
|
||||
}
|
||||
|
||||
func (s *MockSubscriptions) Delete(req *queries.SubscriptionDeleteRequest) (orm.Result, error) {
|
||||
return s.ORMResponse, s.Error
|
||||
}
|
||||
|
||||
func (s *MockSubscriptions) Load(sub *common.Subscription) error {
|
||||
return s.Error
|
||||
|
||||
}
|
||||
|
||||
func (s *MockSubscriptions) Count(filter *common.Subscription) (int, error) {
|
||||
return len(s.ListResult), s.Error
|
||||
}
|
||||
|
||||
func (s *MockSubscriptions) Create(subtype *common.SubscriptionType, carToDriver *common.CarToDriver) (*common.Subscription, error) {
|
||||
if s.ItemResult == nil {
|
||||
return nil, s.Error
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
s.ItemResult.Name = subtype.Name
|
||||
s.ItemResult.SubscriptionTypeID = subtype.ID
|
||||
s.ItemResult.CreatedAt = &now
|
||||
s.ItemResult.UpdatedAt = &now
|
||||
|
||||
return s.ItemResult, s.Error
|
||||
}
|
||||
37
pkg/db/queries/mocks/subscriptiontypes.go
Normal file
37
pkg/db/queries/mocks/subscriptiontypes.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockSubscriptionTypes struct {
|
||||
ORMResult orm.Result
|
||||
Error error
|
||||
ListResult []common.SubscriptionType
|
||||
}
|
||||
|
||||
func (st *MockSubscriptionTypes) Select(filter *common.SubscriptionType) ([]common.SubscriptionType, error) {
|
||||
return st.ListResult, st.Error
|
||||
}
|
||||
|
||||
func (st *MockSubscriptionTypes) Insert(subtype *common.SubscriptionType) (orm.Result, error) {
|
||||
return st.ORMResult, st.Error
|
||||
}
|
||||
|
||||
func (st *MockSubscriptionTypes) Update(subtype *common.SubscriptionType) (orm.Result, error) {
|
||||
return st.ORMResult, st.Error
|
||||
}
|
||||
|
||||
func (st *MockSubscriptionTypes) Delete(subtype *common.SubscriptionType) (orm.Result, error) {
|
||||
return st.ORMResult, st.Error
|
||||
}
|
||||
|
||||
func (st *MockSubscriptionTypes) Load(subtype *common.SubscriptionType) error {
|
||||
return st.Error
|
||||
}
|
||||
|
||||
func (st *MockSubscriptionTypes) Count(filter *common.SubscriptionType) (int, error) {
|
||||
return len(st.ListResult), st.Error
|
||||
}
|
||||
33
pkg/db/queries/mocks/sums_versions.go
Normal file
33
pkg/db/queries/mocks/sums_versions.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockUpdateManifestVersions struct {
|
||||
queries.QueryBase
|
||||
SelectResponse []common.SUMSVersion
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifestVersions) SelectAll(options *queries.PageQueryOptions) ([]common.SUMSVersion, error) {
|
||||
return m.SelectResponse, nil
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifestVersions) SelectAllCount() (int, error) {
|
||||
return len(m.SelectResponse), nil
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifestVersions) Insert(u *common.SUMSVersion) (orm.Result, error) {
|
||||
return m.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifestVersions) Delete(u *common.SUMSVersion) (orm.Result, error) {
|
||||
return m.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifestVersions) Select(version string) (*common.SUMSVersion, error) {
|
||||
return nil, nil
|
||||
}
|
||||
70
pkg/db/queries/mocks/supplier_accounts.go
Normal file
70
pkg/db/queries/mocks/supplier_accounts.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
// CarUpdate query methods
|
||||
type MockSupplierAccounts struct {
|
||||
DBMockHelper
|
||||
MockListResponse []common.SupplierAccount
|
||||
MockSupplierAccount *common.SupplierAccount
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) Count(account *common.SupplierAccount) (int, error) {
|
||||
return len(c.MockListResponse), c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) Delete(account *common.SupplierAccount) (orm.Result, error) {
|
||||
c.LastFilter = account
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) Insert(account *common.SupplierAccount) (orm.Result, error) {
|
||||
c.LastFilter = account
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) Load(account *common.SupplierAccount) error {
|
||||
c.LastFilter = account
|
||||
|
||||
if c.MockSupplierAccount != nil {
|
||||
account.ECUs = c.MockSupplierAccount.ECUs
|
||||
account.ActivatedAt = c.MockSupplierAccount.ActivatedAt
|
||||
}
|
||||
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) Select(account *common.SupplierAccount, paging *queries.PageQueryOptions) ([]common.SupplierAccount, error) {
|
||||
c.LastFilter = account
|
||||
c.LastPaging = paging
|
||||
|
||||
return c.MockListResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) Update(account *common.SupplierAccount) (orm.Result, error) {
|
||||
c.LastFilter = account
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) Approve(email string) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) UpdateTimestamp(email string, activity queries.SupplierTimestamp) (orm.Result, error) {
|
||||
return c.ORMResponse, c.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
c.MockListResponse = list.([]common.SupplierAccount)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MockSupplierAccounts) SetLoadResp(item interface{}) {
|
||||
// fmt.Printf("override SetLoadResp() in %s\n", reflect.TypeOf(item))
|
||||
}
|
||||
43
pkg/db/queries/mocks/supplier_organizations.go
Normal file
43
pkg/db/queries/mocks/supplier_organizations.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
// EccKey query methods
|
||||
type MockSupplierOrganization struct {
|
||||
DBMockHelper
|
||||
MockListResponse []common.SupplierOrganization
|
||||
MockSupplierOrganization *common.SupplierOrganization
|
||||
}
|
||||
|
||||
func (so *MockSupplierOrganization) Count(supplierOrganization *common.SupplierOrganization) (int, error) {
|
||||
return len(so.MockListResponse), so.Error
|
||||
}
|
||||
|
||||
func (so *MockSupplierOrganization) Insert(supplierOrg *common.SupplierOrganization) (orm.Result, error) {
|
||||
return so.ORMResponse, so.Error
|
||||
}
|
||||
|
||||
func (so *MockSupplierOrganization) Update(supplierOrg *common.SupplierOrganization) (orm.Result, error) {
|
||||
return so.ORMResponse, so.Error
|
||||
}
|
||||
|
||||
func (so *MockSupplierOrganization) Delete(supplierOrg *common.SupplierOrganization) (orm.Result, error) {
|
||||
return so.ORMResponse, so.Error
|
||||
}
|
||||
|
||||
func (so *MockSupplierOrganization) Select(supplierOrg *common.SupplierOrganization, paging *queries.PageQueryOptions) ([]common.SupplierOrganization, error) {
|
||||
so.LastFilter = supplierOrg
|
||||
so.LastPaging = paging
|
||||
|
||||
return so.MockListResponse, so.Error
|
||||
}
|
||||
|
||||
func (c *MockSupplierOrganization) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
c.MockListResponse = list.([]common.SupplierOrganization)
|
||||
}
|
||||
}
|
||||
29
pkg/db/queries/mocks/swversion_rxswin.go
Normal file
29
pkg/db/queries/mocks/swversion_rxswin.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockSwVersionRxSwin struct {
|
||||
queries.QueryBase
|
||||
SelectResponse []common.SwVersionRxSwin
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockSwVersionRxSwin) SelectByVersion(version string, options *queries.PageQueryOptions) ([]common.SwVersionRxSwin, error) {
|
||||
return m.SelectResponse, nil
|
||||
}
|
||||
|
||||
func (m *MockSwVersionRxSwin) SelectCountByVersion(version string) (int, error) {
|
||||
return len(m.SelectResponse), nil
|
||||
}
|
||||
|
||||
func (m *MockSwVersionRxSwin) Insert(swVersionRxSwin *common.SwVersionRxSwin) (orm.Result, error) {
|
||||
return m.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (m *MockSwVersionRxSwin) Delete(model *common.SwVersionRxSwin) (orm.Result, error) {
|
||||
return m.ORMResponse, nil
|
||||
}
|
||||
26
pkg/db/queries/mocks/symkeys.go
Normal file
26
pkg/db/queries/mocks/symkeys.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
)
|
||||
|
||||
// SymKey query methods
|
||||
type MockSymKeys struct {
|
||||
DBMockHelper
|
||||
MockListResponse []common.SymKeys
|
||||
MockSymKeys common.SymKeys
|
||||
}
|
||||
|
||||
func (sk *MockSymKeys) Insert(keys common.SymKeys) (orm.Result, error) {
|
||||
return sk.ORMResponse, sk.Error
|
||||
}
|
||||
|
||||
func (sk *MockSymKeys) SelectAll() ([]common.SymKeys, error) {
|
||||
return sk.MockListResponse, sk.Error
|
||||
}
|
||||
|
||||
func (sk *MockSymKeys) SelectByVIN(vin string) (common.SymKeys, error) {
|
||||
return sk.MockSymKeys, sk.Error
|
||||
}
|
||||
23
pkg/db/queries/mocks/tags.go
Normal file
23
pkg/db/queries/mocks/tags.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type MockTags struct {
|
||||
queries.QueryBase
|
||||
ReceivedTags []string
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (t *MockTags) Update(car *common.Car) (orm.Result, error) {
|
||||
t.ReceivedTags = car.Tags
|
||||
return t.ORMResponse, nil
|
||||
}
|
||||
|
||||
func (t *MockTags) UpdateDistinctTags(car *common.Car) (orm.Result, error) {
|
||||
t.ReceivedTags = car.Tags
|
||||
return t.ORMResponse, nil
|
||||
}
|
||||
137
pkg/db/queries/mocks/updatemanifests.go
Normal file
137
pkg/db/queries/mocks/updatemanifests.go
Normal file
@@ -0,0 +1,137 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
"fiskerinc.com/modules/db/queries"
|
||||
"fiskerinc.com/modules/validator"
|
||||
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type MockFingerprintParams struct {
|
||||
Serial string
|
||||
Time time.Time
|
||||
}
|
||||
|
||||
func (m *MockFingerprintParams) ManifestSerial() string {
|
||||
return m.Serial
|
||||
}
|
||||
|
||||
func (m *MockFingerprintParams) CurTime() time.Time {
|
||||
return m.Time
|
||||
}
|
||||
|
||||
type MockUpdateManifests struct {
|
||||
queries.QueryBase
|
||||
SelectResponse []common.UpdateManifest
|
||||
SelectByVINResponse []common.StatusManifest
|
||||
LoadResponse *common.UpdateManifest
|
||||
ECUUpdatesMock func(man *common.UpdateManifestECU, vin string) ([]*common.UpdateManifestECU, error)
|
||||
FlashPackManifest common.UpdateManifest
|
||||
DBMockHelper
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Count(filter common.UpdateManifest) (int, error) {
|
||||
return len(m.SelectResponse), m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Delete(manifest *common.UpdateManifest) (orm.Result, error) {
|
||||
err := validator.ValidateIDField(manifest.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Insert(manifest *common.UpdateManifest) (orm.Result, error) {
|
||||
manifest.ID += 1
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) ECUInsert(ecu *common.UpdateManifestECU) (orm.Result, error) {
|
||||
ecu.ID = 1
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) FileInsert(file *common.UpdateManifestFile) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Select(filter *common.UpdateManifest, paging *queries.PageQueryOptions) ([]common.UpdateManifest, error) {
|
||||
m.LastFilter = filter
|
||||
m.LastPaging = paging
|
||||
|
||||
return m.SelectResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Archive(ids []int64, active bool) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) SelectByVIN(vin string, paging *queries.PageQueryOptions) ([]common.StatusManifest, error) {
|
||||
m.LastPaging = paging
|
||||
|
||||
return m.SelectByVINResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Update(manifest *common.UpdateManifest) (orm.Result, error) {
|
||||
m.LastFilter = manifest
|
||||
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Load(manifest *common.UpdateManifest) error {
|
||||
m.LastFilter = manifest
|
||||
|
||||
if m.LoadResponse != nil {
|
||||
m.LoadResponse.ID = manifest.ID
|
||||
data, err := json.Marshal(m.LoadResponse)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
err = json.Unmarshal(data, manifest)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
return m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) Search(filter common.UpdateManifestSearch, paging *queries.PageQueryOptions) ([]common.UpdateManifest, error) {
|
||||
m.LastFilter = &filter
|
||||
m.LastPaging = paging
|
||||
|
||||
return m.SelectResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) SearchCount(filter common.UpdateManifestSearch) (int, error) {
|
||||
m.LastFilter = &filter
|
||||
|
||||
return len(m.SelectResponse), m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) SetListResp(list interface{}) {
|
||||
if list != nil {
|
||||
m.SelectResponse = list.([]common.UpdateManifest)
|
||||
} else {
|
||||
m.SelectResponse = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) ECURollback(man *common.UpdateManifestECU, vin string) ([]*common.UpdateManifestECU, error) {
|
||||
return m.ECUUpdatesMock(man, vin)
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) AddSUMSVersion(manifest *common.UpdateManifest) (orm.Result, error) {
|
||||
return m.ORMResponse, m.Error
|
||||
}
|
||||
|
||||
func (m *MockUpdateManifests) SelectFlashPackByVersion(versionNumber string) (manifest common.UpdateManifest, err error) {
|
||||
return m.FlashPackManifest, nil
|
||||
}
|
||||
Reference in New Issue
Block a user