package handlers_test import ( "testing" ) func TestHandlers_HandleECUDTCGet(t *testing.T) { /* db := services.GetDB() dtcs := []common.DTC_ECU{ { ID: 196, VIN: "1GNGC26RXXJ407648", ECU: "AMP", DTC: []byte{9, 81, 118, 19}, Epoch_usec: 1624485598, }, { ID: 197, VIN: "1GNGC26RXXJ407648", ECU: "AMP", TroubleCode: 12, DTC: []byte{9, 81, 118, 19}, Epoch_usec: 1624485598, }, } tests := map[string]struct { vin string ecu string start string end string dtcs q.ECUInterface expStatus int expBody string }{ "success": { vin: "1GNGC26RXXJ407648", ecu: "AMP", start: "", end: "", dtcs: &mocks.MockEcuDtc{ SelectDTCECUResponse: dtcs, }, expStatus: http.StatusOK, expBody: `{"data":[{"id":196,"vin":"1GNGC26RXXJ407648","ecu_name":"AMP","dtc":"CVF2Ew==","trouble_code":0,"status_byte":0,"epoch_usec":1624485598},{"id":197,"vin":"1GNGC26RXXJ407648","ecu_name":"AMP","dtc":"CVF2Ew==","trouble_code":12,"status_byte":0,"epoch_usec":1624485598}]}`, }, "invalid_vin": { vin: "INVALID_VIN", ecu: "AMP", start: "", end: "", dtcs: &mocks.MockEcuDtc{}, expStatus: http.StatusBadRequest, expBody: `{"message":"vin|vinsuffix vin|vinsuffix ","error":"Bad Request"}`, }, } for name, tt := range tests { t.Run(name, func(t *testing.T) { w := httptest.NewRecorder() db.SetDTCECU(tt.dtcs) p := httprouter.Params{ {"vin", tt.vin}, {"ecu", tt.ecu}, {"trouble_code", "12"}, {"start_time", tt.start}, {"end_time", tt.end}, } ctx := context.WithValue(context.Background(), httprouter.ParamsKey, p) request := httptest.NewRequest(http.MethodGet, "http://example.com/dtcs/"+tt.vin, nil). WithContext(ctx) handlers.HandleECUDTCGet(w, request) assert.Equal(t, tt.expStatus, w.Code) assert.Equal(t, tt.expBody, w.Body.String()) }) } */ }