55 "io/ioutil"
66 "log"
77 "os"
8+ "strings"
89 "testing"
910)
1011
@@ -145,7 +146,7 @@ var apiTestList = []APITestCase{
145146 },
146147}
147148
148- func TestTrip (t * testing.T ) {
149+ func TestTripApis (t * testing.T ) {
149150 router := NewRouter ()
150151 var debug , present = os .LookupEnv ("DEBUG_LOGGING" )
151152
@@ -155,41 +156,40 @@ func TestTrip(t *testing.T) {
155156 // if debug env is not present or false, do not log debug output to console
156157 InitLogging (os .Stdout , ioutil .Discard , os .Stdout )
157158 }
158- RunAPITests (t , router , apiTestList [0 :4 ])
159+ RunAPITests (t , router , apiTestList [0 :3 ])
159160
160- // // setup update trip test (URL, Body, expected Response)
161- // apiTestList[4 ].URL = strings.Replace(apiTestList[4 ].URL, "{tripID}", TripFromStr(apiTestList[3 ].ActualResponse).ID, 1)
162- // apiTestList[4 ].Body = GetUpdateTrip(apiTestList[3 ].ActualResponse, apiTestList[4 ].Body)
163- // apiTestList[4 ].ExpectedResponse = apiTestList[4 ].Body
161+ // setup update trip test (URL, Body, expected Response)
162+ apiTestList [3 ].URL = strings .Replace (apiTestList [3 ].URL , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
163+ apiTestList [3 ].Body = GetUpdateTrip (apiTestList [2 ].ActualResponse , apiTestList [3 ].Body )
164+ apiTestList [3 ].ExpectedResponse = apiTestList [3 ].Body
164165
165- // // setup create trip point test
166- // apiTestList[5 ].URL = strings.Replace(apiTestList[5 ].URL, "{tripID}", TripFromStr(apiTestList[3 ].ActualResponse).ID, 1)
167- // apiTestList[5 ].Body = strings.Replace(apiTestList[5 ].Body, "{tripID}", TripFromStr(apiTestList[3 ].ActualResponse).ID, 1)
166+ // setup create trip point test
167+ apiTestList [4 ].URL = strings .Replace (apiTestList [4 ].URL , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
168+ apiTestList [4 ].Body = strings .Replace (apiTestList [4 ].Body , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
168169
169- // // run update trip and create trip point tests
170- // RunAPITests(t, router, apiTestList[4:6 ])
170+ // run update trip and create trip point tests
171+ RunAPITests (t , router , apiTestList [3 : 5 ])
171172
172- // // setup update trip point test
173- // apiTestList[6].URL = strings.Replace(apiTestList[6].URL, "{tripID}", TripFromStr(apiTestList[3].ActualResponse).ID, 1)
174- // apiTestList[6].URL = strings.Replace(apiTestList[6].URL, "{tripPointID}", TripPointFromStr(apiTestList[5].ActualResponse).ID, 1)
175- // apiTestList[6].Body = GetUpdateTripPoint(apiTestList[5].ActualResponse, apiTestList[6].Body)
176- // //apiTestList[6].ExpectedResponse = apiTestList[6].Body
173+ // setup update trip point test
174+ apiTestList [5 ].URL = strings .Replace (apiTestList [5 ].URL , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
175+ apiTestList [5 ].URL = strings .Replace (apiTestList [5 ].URL , "{tripPointID}" , TripPointFromStr (apiTestList [4 ].ActualResponse ).ID , 1 )
176+ apiTestList [5 ].Body = GetUpdateTripPoint (apiTestList [4 ].ActualResponse , apiTestList [5 ].Body )
177177
178- // // setup read trip points for trip test
179- // apiTestList[7 ].URL = strings.Replace(apiTestList[7 ].URL, "{tripID}", TripFromStr(apiTestList[3 ].ActualResponse).ID, 1)
178+ // setup read trip points for trip test
179+ apiTestList [6 ].URL = strings .Replace (apiTestList [6 ].URL , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
180180
181181 // // setup ready trip points by trip point id test
182- // apiTestList[8 ].URL = strings.Replace(apiTestList[8 ].URL, "{tripID}", TripFromStr(apiTestList[3 ].ActualResponse).ID, 1)
183- // apiTestList[8 ].URL = strings.Replace(apiTestList[8 ].URL, "{tripPointID}", TripPointFromStr(apiTestList[5 ].ActualResponse).ID, 1)
182+ apiTestList [7 ].URL = strings .Replace (apiTestList [7 ].URL , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
183+ apiTestList [7 ].URL = strings .Replace (apiTestList [7 ].URL , "{tripPointID}" , TripPointFromStr (apiTestList [4 ].ActualResponse ).ID , 1 )
184184
185185 // //setup delete trip point test
186- // apiTestList[9 ].URL = strings.Replace(apiTestList[9 ].URL, "{tripID}", TripFromStr(apiTestList[3 ].ActualResponse).ID, 1)
187- // apiTestList[9 ].URL = strings.Replace(apiTestList[9 ].URL, "{tripPointID}", TripPointFromStr(apiTestList[5 ].ActualResponse).ID, 1)
186+ apiTestList [8 ].URL = strings .Replace (apiTestList [8 ].URL , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
187+ apiTestList [8 ].URL = strings .Replace (apiTestList [8 ].URL , "{tripPointID}" , TripPointFromStr (apiTestList [4 ].ActualResponse ).ID , 1 )
188188
189- // // setup delete test (URL)
190- // apiTestList[10 ].URL = strings.Replace(apiTestList[10 ].URL, "{tripID}", TripFromStr(apiTestList[3 ].ActualResponse).ID, 1)
191- // // run update test
192- // RunAPITests(t, router, apiTestList[6 :10])
189+ // setup delete test (URL)
190+ apiTestList [9 ].URL = strings .Replace (apiTestList [9 ].URL , "{tripID}" , TripFromStr (apiTestList [2 ].ActualResponse ).ID , 1 )
191+ // run update test
192+ RunAPITests (t , router , apiTestList [5 :10 ])
193193}
194194
195195func GetUpdateTrip (tripCreate string , tripUpdate string ) string {
@@ -218,7 +218,7 @@ func GetUpdateTripPoint(tripPointCreate string, tripPointUpdate string) string {
218218func TripFromStr (tripStr string ) Trip {
219219 trip := Trip {}
220220
221- Debug .Println (tripStr )
221+ Debug .Println ("DEBUG: TripFromStr - " + tripStr )
222222
223223 errCreate := json .Unmarshal ([]byte (tripStr ), & trip )
224224 if errCreate != nil {
@@ -232,6 +232,8 @@ func TripFromStr(tripStr string) Trip {
232232func TripPointFromStr (tripPointStr string ) TripPoint {
233233 tripPoint := TripPoint {}
234234
235+ Debug .Println ("DEBUG: TripPointFromStr - " + tripPointStr )
236+
235237 errCreate := json .Unmarshal ([]byte (tripPointStr ), & tripPoint )
236238 if errCreate != nil {
237239 log .Println ("TripPointFromStr - Invalid trip point string" )
0 commit comments