package usecase_helpers import ( "encoding/json" "os" "testing" "fiskerinc.com/modules/common" "fiskerinc.com/modules/db" "fiskerinc.com/modules/db/queries" "github.com/stretchr/testify/assert" ) func init() { os.Setenv("NO_CDS_ECUS", "VCU, NTN") } func TestCDSRenameAndRemoval(t *testing.T) { common.BuildFilterECUConfigurationMap() cdsMap := map[string]string{ "GW": "000547303031313632FF7CFF7F0040", "VCU": "0003473030313136320102010A", "PDU": "00024730303131363202768F", "EPS": "000147303031313632011D", "EPS2": "000147303031313632011D", "ESP": "000F47303031313632000001012301027600000101000002B0", } expectedMap := map[string]string{ "GW": "000547303031313632FF7CFF7F0040", "EPS1": "000147303031313632011D", "EPS2": "000147303031313632011D", "ESP": "000F47303031313632000001012301027600000101000002B0", "OBC": "00024730303131363202768F", } cdsMap = cdsNameTransform(cdsMap) cdsMap = cdsRemoval(cdsMap) if !assert.Equal(t, expectedMap, cdsMap) { t.Fail() } } func TestGetCDSFromDB(t *testing.T) { os.Setenv("DB_USER", "fiskercloud") os.Setenv("DB_PASSWORD", "ywo5ea8OPN1E4V9&") os.Setenv("DB_HOST", "cec-prd-cloud-2.postgres.database.azure.com") os.Setenv("DB_NAME", "postgres") os.Setenv("DB_SSLMODE", "require") client := &db.DBClient{} client.RegisterManyToManyRel([]interface{}{ (*common.CarToDriver)(nil), }) err := client.InitSchema([]interface{}{ (*common.UpdateManifest)(nil), (*common.Car)(nil), (*common.CarToDriver)(nil), (*common.CarUpdateStatus)(nil), (*common.CarUpdate)(nil), (*common.FileKey)(nil), (*common.RatePlanTMobile)(nil), }) if err != nil { t.Fatal(err) } carConfigData := &queries.CarConfigData{} carConfigData.SetClient(client) res, err := getStoredFeatureCodes("VCF1ZBU28PG002114", carConfigData) if err != nil { t.Fatal(err) } featureCodes := make([]string, 0, len(res.Features)) for _, c := range res.Features { featureCodes = append(featureCodes, c.FeatureCode) } featureCodesString, _ := json.Marshal(featureCodes) _ = featureCodesString t.Logf("%s\n", featureCodesString) } func TestBCMBeepOverwrite(t *testing.T){ // Generated on local test ODX. withBeep := "001247303032313134000100010001010101000201010101010073" noBeep := "0012473030323131340001000100010101010000010101010100C9" expectNoChange := overwriteBCMBeep(noBeep) if expectNoChange != noBeep { t.Errorf("expected No Change between \n%s\n%s\n", noBeep, expectNoChange) } expectChange := overwriteBCMBeep(withBeep) if expectChange != noBeep { t.Errorf("expected Change to match between \n%s\n%s\n", noBeep, expectChange) } } // Should change these tests to ignore the headers, and only check the actual byteage func TestBCMSequentialLightingOverwrite(t *testing.T){ noLight := "001247303032313732000100000201010101020001010001010071" withLight := "0012473030323137320001000102010101010200010100010100F0" expectNoChange := overwriteBCMSequentialLighting(withLight) if expectNoChange != withLight { t.Errorf("expected No Change between \n%s\n%s\n", withLight, expectNoChange) } expectChange := overwriteBCMSequentialLighting(noLight) if expectChange != withLight { t.Errorf("expected Change to match between \n%s\n%s\n", withLight, expectChange) } } func TestICCOverwrite(t *testing.T){ withoutHotSpot := "010047303032313134230108400000020401010001000000010000000001010000000001020000000001000000010000000100000000000000000001010100000000000001010101000100000000010000000000000000000001000101000102010101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E5" // Ivans with 130100 withHotSpot := "0100473030323131342301084000000204010100010000000100000000010100000000010200000000010000000100000001000000000000000000010101000100000000010101010001000000000100000000000000000000010001010001020101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009D" // Ivans -> MID_BLUE_MATTE from COL 57 the value 4 expectedChange := overwriteICCHotSpot(withoutHotSpot) if expectedChange == withoutHotSpot { t.Error("my life is meanignless") } if expectedChange != withHotSpot { t.Errorf("Expected {2} to become {1} \n%s\n%s\n", withHotSpot, expectedChange) } expectNoChange := overwriteICCHotSpot(withHotSpot) if expectNoChange != withHotSpot { t.Errorf("expected No Change to match between \n%s\n%s\n", withHotSpot, expectNoChange) } } // Give a input, and check if the bit is correct func TestHasICCHotSpot(t *testing.T) { input := "0100473030323131342301084000000204010100010000000100000000010100000000010200000000010000000100000001000000000000000000010101000100000000010101010001000000000100000000000000000000010001010001020101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009D" out := overwriteICCHotSpot(input) if input != out { t.Fail() } }