How to use Stop method of test_helpers Package

Best Ginkgo code snippet using test_helpers.Stop

ingester_test.go

Source:ingester_test.go Github

copy

Full Screen

...135 repository.RedisPoolDial(func() (redis.Conn, error) {136 return redis.Dial("tcp", localityNamesDB.Addr())137 }),138 }...),139 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{140 repository.RedisPoolDial(func() (redis.Conn, error) {141 return redis.Dial("tcp", stopsInAreaDB.Addr())142 }),143 }...),144 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{145 repository.RedisPoolDial(func() (redis.Conn, error) {146 return redis.Dial("tcp", circularServicesDB.Addr())147 }),148 }...),149 circularServices: make(map[string]*string),150 localityNames: make(map[string]*string),151 stopsInArea: make(map[string]*string),152 }153 event := buildSnsEvent(t, newDeparture1, newDeparture2)154 if err := in.Handler(event); err != nil {155 t.Error(err)156 return157 }158 departuresDB.CheckList(t, locationAtcocode, []string{string(newDeparture1Expectation), string(newDeparture2Expectation)}...)159 departuresDB.CheckList(t, stopAreaAtcocode, []string{string(newDeparture1Expectation), string(newDeparture2Expectation)}...)160 })161 t.Run("creates new data in the cache", func(t *testing.T) {162 newExpectedDepartureTime1 := test_helpers.AdjustTime(now, "1m")163 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1234, test_helpers.AdjustTime(now, "-2m"), &newExpectedDepartureTime1, locationAtcocode, &locationStand, "1800WA12481", "Turning Circle", "534", "ANWE")164 newDeparture1Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1234, test_helpers.AdjustTime(now, "-2m"), &newExpectedDepartureTime1, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")165 newDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1235, test_helpers.AdjustTime(now, "2m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Hobbiton Interchange", "525", "VISB")166 newDeparture2Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1235, test_helpers.AdjustTime(now, "2m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")167 localityNamesDB, err := miniredis.Run()168 if err != nil {169 t.Fatal(err)170 }171 defer localityNamesDB.Close()172 if err := localityNamesDB.Set("1800WA12481", "Hobbiton"); err != nil {173 t.Fatal(err)174 }175 departuresDB, err := miniredis.Run()176 if err != nil {177 t.Fatal(err)178 }179 defer departuresDB.Close()180 stopsInAreaDB, err := miniredis.Run()181 if err != nil {182 t.Fatal(err)183 }184 defer stopsInAreaDB.Close()185 if err := stopsInAreaDB.Set(locationAtcocode, stopAreaAtcocode); err != nil {186 t.Fatal(err)187 }188 circularServicesDB, err := miniredis.Run()189 if err != nil {190 t.Fatal(err)191 }192 defer circularServicesDB.Close()193 if err := circularServicesDB.Set("VISB525", "Mordor circular"); err != nil {194 t.Fatal(err)195 }196 in := Ingester{197 Logger: dlog.NewLogger([]dlog.LoggerOption{198 dlog.LoggerSetOutput(ioutil.Discard),199 }...),200 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{201 repository.RedisPoolDial(func() (redis.Conn, error) {202 return redis.Dial("tcp", departuresDB.Addr())203 }),204 }...),205 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{206 repository.RedisPoolDial(func() (redis.Conn, error) {207 return redis.Dial("tcp", localityNamesDB.Addr())208 }),209 }...),210 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{211 repository.RedisPoolDial(func() (redis.Conn, error) {212 return redis.Dial("tcp", stopsInAreaDB.Addr())213 }),214 }...),215 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{216 repository.RedisPoolDial(func() (redis.Conn, error) {217 return redis.Dial("tcp", circularServicesDB.Addr())218 }),219 }...),220 circularServices: make(map[string]*string),221 localityNames: make(map[string]*string),222 stopsInArea: make(map[string]*string),223 }224 event := buildSnsEvent(t, newDeparture1, newDeparture2)225 if err := in.Handler(event); err != nil {226 t.Error(err)227 return228 }229 departuresDB.CheckList(t, locationAtcocode, []string{string(newDeparture1Expectation), string(newDeparture2Expectation)}...)230 departuresDB.CheckList(t, stopAreaAtcocode, []string{string(newDeparture1Expectation), string(newDeparture2Expectation)}...)231 })232 t.Run("removes expired data from the cache", func(t *testing.T) {233 cachedExpectedDepartureTime1 := test_helpers.AdjustTime(now, "-1m")234 cachedDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1234, test_helpers.AdjustTime(now, "-2m"), &cachedExpectedDepartureTime1, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")235 cachedExpectedDepartureTime2 := test_helpers.AdjustTime(now, "1m")236 cachedDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1235, test_helpers.AdjustTime(now, "-2m"), &cachedExpectedDepartureTime2, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")237 cachedDeparture3 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1236, test_helpers.AdjustTime(now, "-2m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")238 cachedDeparture4 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1237, test_helpers.AdjustTime(now, "2m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "VISB", "525")239 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "3m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Turning Circle", "534", "ANWE")240 newDeparture1Expectaton := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "3m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")241 newDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1239, test_helpers.AdjustTime(now, "4m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Hobbiton Interchange", "525", "VISB")242 newDeparture2Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1239, test_helpers.AdjustTime(now, "4m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")243 localityNamesDB, err := miniredis.Run()244 if err != nil {245 t.Fatal(err)246 }247 defer localityNamesDB.Close()248 if err := localityNamesDB.Set("1800WA12481", "Hobbiton"); err != nil {249 t.Fatal(err)250 }251 departuresDB, err := miniredis.Run()252 if err != nil {253 t.Fatal(err)254 }255 defer departuresDB.Close()256 if _, err := departuresDB.Push(locationAtcocode, []string{string(cachedDeparture1), string(cachedDeparture2), string(cachedDeparture3), string(cachedDeparture4)}...); err != nil {257 t.Fatal(err)258 }259 if _, err := departuresDB.Push(stopAreaAtcocode, []string{string(cachedDeparture1), string(cachedDeparture2), string(cachedDeparture3), string(cachedDeparture4)}...); err != nil {260 t.Fatal(err)261 }262 stopsInAreaDB, err := miniredis.Run()263 if err != nil {264 t.Fatal(err)265 }266 defer stopsInAreaDB.Close()267 if err := stopsInAreaDB.Set(locationAtcocode, stopAreaAtcocode); err != nil {268 t.Fatal(err)269 }270 circularServicesDB, err := miniredis.Run()271 if err != nil {272 t.Fatal(err)273 }274 defer circularServicesDB.Close()275 if err := circularServicesDB.Set("VISB525", "Mordor circular"); err != nil {276 t.Fatal(err)277 }278 in := Ingester{279 Logger: dlog.NewLogger([]dlog.LoggerOption{280 dlog.LoggerSetOutput(ioutil.Discard),281 }...),282 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{283 repository.RedisPoolDial(func() (redis.Conn, error) {284 return redis.Dial("tcp", departuresDB.Addr())285 }),286 }...),287 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{288 repository.RedisPoolDial(func() (redis.Conn, error) {289 return redis.Dial("tcp", localityNamesDB.Addr())290 }),291 }...),292 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{293 repository.RedisPoolDial(func() (redis.Conn, error) {294 return redis.Dial("tcp", stopsInAreaDB.Addr())295 }),296 }...),297 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{298 repository.RedisPoolDial(func() (redis.Conn, error) {299 return redis.Dial("tcp", circularServicesDB.Addr())300 }),301 }...),302 circularServices: make(map[string]*string),303 localityNames: make(map[string]*string),304 stopsInArea: make(map[string]*string),305 }306 event := buildSnsEvent(t, newDeparture1, newDeparture2)307 if err := in.Handler(event); err != nil {308 t.Error(err)309 return310 }311 departuresDB.CheckList(t, locationAtcocode, []string{string(cachedDeparture2), string(cachedDeparture4), string(newDeparture1Expectaton), string(newDeparture2Expectation)}...)312 departuresDB.CheckList(t, stopAreaAtcocode, []string{string(cachedDeparture2), string(cachedDeparture4), string(newDeparture1Expectaton), string(newDeparture2Expectation)}...)313 })314 t.Run("removes expired data from source before calling any caches", func(t *testing.T) {315 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "-1m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Turning Circle", "534", "ANWE")316 newDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1239, test_helpers.AdjustTime(now, "-1m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Hobbiton Interchange", "525", "VISB")317 localityNamesDB, err := miniredis.Run()318 if err != nil {319 t.Fatal(err)320 }321 defer localityNamesDB.Close()322 departuresDB, err := miniredis.Run()323 if err != nil {324 t.Fatal(err)325 }326 defer departuresDB.Close()327 stopsInAreaDB, err := miniredis.Run()328 if err != nil {329 t.Fatal(err)330 }331 defer stopsInAreaDB.Close()332 if err := stopsInAreaDB.Set(locationAtcocode, stopAreaAtcocode); err != nil {333 t.Fatal(err)334 }335 circularServicesDB, err := miniredis.Run()336 if err != nil {337 t.Fatal(err)338 }339 defer circularServicesDB.Close()340 in := Ingester{341 Logger: dlog.NewLogger([]dlog.LoggerOption{342 dlog.LoggerSetOutput(ioutil.Discard),343 }...),344 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{345 repository.RedisPoolDial(func() (redis.Conn, error) {346 return redis.Dial("tcp", departuresDB.Addr())347 }),348 }...),349 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{350 repository.RedisPoolDial(func() (redis.Conn, error) {351 return redis.Dial("tcp", localityNamesDB.Addr())352 }),353 }...),354 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{355 repository.RedisPoolDial(func() (redis.Conn, error) {356 return redis.Dial("tcp", stopsInAreaDB.Addr())357 }),358 }...),359 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{360 repository.RedisPoolDial(func() (redis.Conn, error) {361 return redis.Dial("tcp", circularServicesDB.Addr())362 }),363 }...),364 circularServices: make(map[string]*string),365 localityNames: make(map[string]*string),366 stopsInArea: make(map[string]*string),367 }368 event := buildSnsEvent(t, newDeparture1, newDeparture2)369 if err := in.Handler(event); err != nil {370 t.Error(err)371 return372 }373 if _, err := departuresDB.List(locationAtcocode); err == nil {374 t.Errorf("list for %s should be empty", locationAtcocode)375 }376 if _, err := departuresDB.List(stopAreaAtcocode); err == nil {377 t.Errorf("list for %s should be empty", stopAreaAtcocode)378 }379 })380 t.Run("handles data for multiple locations", func(t *testing.T) {381 // Should remove this382 location1CachedDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1233, test_helpers.AdjustTime(now, "-10s"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")383 // Should update this...384 location1CachedExpectedDepartureTime2 := test_helpers.AdjustTime(now, "-1m")385 location1CachedDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1234, test_helpers.AdjustTime(now, "-2m"), &location1CachedExpectedDepartureTime2, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")386 // ...with this387 location1NewExpectedDepartureTime2 := test_helpers.AdjustTime(now, "1m")388 location1NewDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1234, test_helpers.AdjustTime(now, "-2m"), &location1NewExpectedDepartureTime2, locationAtcocode, &locationStand, "1800WA12481", "Turning Circle", "534", "ANWE")389 location1NewDeparture2Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1234, test_helpers.AdjustTime(now, "-2m"), &location1NewExpectedDepartureTime2, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")390 // Should update this...391 location1CachedDeparture3 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1235, test_helpers.AdjustTime(now, "2m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")392 // ...with this393 location1NewDeparture3 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1235, test_helpers.AdjustTime(now, "3m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Hobbiton Interchange", "525", "VISB")394 location1NewDeparture3Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1235, test_helpers.AdjustTime(now, "3m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")395 // Should create this396 location1NewDeparture4 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1236, test_helpers.AdjustTime(now, "4m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Turning Circle", "534", "ANWE")397 location1NewDeparture4Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1236, test_helpers.AdjustTime(now, "4m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")398 // Should remove this...399 location2CachedDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1333, test_helpers.AdjustTime(now, "-1m"), nil, extraLocationAtcocode, &extraLocationStand, extraLocationAtcocode, "Bree circular", "561", "FMAN")400 // ...and this401 location2CachedDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1333, test_helpers.AdjustTime(now, "-1s"), nil, extraLocationAtcocode, &extraLocationStand, "1800SB45111", "Minas Tirith", "37", "SCMN")402 // Should update this...403 location2CachedExpectedDepartureTime3 := test_helpers.AdjustTime(now, "-1m")404 location2CachedDeparture3 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1334, test_helpers.AdjustTime(now, "-1m"), &location2CachedExpectedDepartureTime3, extraLocationAtcocode, &extraLocationStand, "1800SB45111", "Minas Tirith", "37", "SCMN")405 // ...with this406 location2NewExpectedDepartureTime3 := test_helpers.AdjustTime(now, "2m")407 location2NewDeparture3 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1334, test_helpers.AdjustTime(now, "-1m"), &location2NewExpectedDepartureTime3, extraLocationAtcocode, &extraLocationStand, "1800SB45111", "Parker Street", "37", "SCMN")408 location2NewDeparture3Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1334, test_helpers.AdjustTime(now, "-1m"), &location2NewExpectedDepartureTime3, extraLocationAtcocode, &extraLocationStand, "1800SB45111", "Minas Tirith", "37", "SCMN")409 // Should update this...410 location2CachedDeparture4 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1335, test_helpers.AdjustTime(now, "3m"), nil, extraLocationAtcocode, &extraLocationStand, extraLocationAtcocode, "Bree circular", "561", "FMAN")411 // ...with this412 location2NewDeparture4 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1335, test_helpers.AdjustTime(now, "4m"), nil, extraLocationAtcocode, &extraLocationStand, extraLocationAtcocode, "Hobbiton Interchange", "561", "FMAN")413 location2NewDeparture4Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1335, test_helpers.AdjustTime(now, "4m"), nil, extraLocationAtcocode, &extraLocationStand, extraLocationAtcocode, "Bree circular", "561", "FMAN")414 // Should create this...415 location2NewDeparture5 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1336, test_helpers.AdjustTime(now, "5m"), nil, extraLocationAtcocode, &extraLocationStand, "1800SB45111", "Parker Street", "37", "SCMN")416 location2NewDeparture5Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1336, test_helpers.AdjustTime(now, "5m"), nil, extraLocationAtcocode, &extraLocationStand, "1800SB45111", "Minas Tirith", "37", "SCMN")417 // ...and this418 location2NewDeparture6 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1337, test_helpers.AdjustTime(now, "6m"), nil, extraLocationAtcocode, &extraLocationStand, extraLocationAtcocode, "Hobbiton Interchange", "561", "FMAN")419 location2NewDeparture6Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0s"), 1337, test_helpers.AdjustTime(now, "6m"), nil, extraLocationAtcocode, &extraLocationStand, extraLocationAtcocode, "Bree circular", "561", "FMAN")420 localityNamesDB, err := miniredis.Run()421 if err != nil {422 t.Fatal(err)423 }424 defer localityNamesDB.Close()425 if err := localityNamesDB.Set("1800WA12481", "Hobbiton"); err != nil {426 t.Fatal(err)427 }428 if err := localityNamesDB.Set("1800SB45111", "Minas Tirith"); err != nil {429 t.Fatal(err)430 }431 departuresDB, err := miniredis.Run()432 if err != nil {433 t.Fatal(err)434 }435 defer departuresDB.Close()436 if _, err := departuresDB.Push(locationAtcocode, []string{437 string(location1CachedDeparture1),438 string(location1CachedDeparture2),439 string(location1CachedDeparture3),440 }...); err != nil {441 t.Fatal(err)442 }443 if _, err := departuresDB.Push(extraLocationAtcocode, []string{444 string(location2CachedDeparture1),445 string(location2CachedDeparture2),446 string(location2CachedDeparture3),447 string(location2CachedDeparture4),448 }...); err != nil {449 t.Fatal(err)450 }451 if _, err := departuresDB.Push(stopAreaAtcocode, []string{452 string(location1CachedDeparture1),453 string(location1CachedDeparture2),454 string(location1CachedDeparture3),455 string(location2CachedDeparture1),456 string(location2CachedDeparture2),457 string(location2CachedDeparture3),458 string(location2CachedDeparture4),459 }...); err != nil {460 t.Fatal(err)461 }462 stopsInAreaDB, err := miniredis.Run()463 if err != nil {464 t.Fatal(err)465 }466 defer stopsInAreaDB.Close()467 if err := stopsInAreaDB.Set(locationAtcocode, stopAreaAtcocode); err != nil {468 t.Fatal(err)469 }470 if err := stopsInAreaDB.Set(extraLocationAtcocode, stopAreaAtcocode); err != nil {471 t.Fatal(err)472 }473 circularServicesDB, err := miniredis.Run()474 if err != nil {475 t.Fatal(err)476 }477 defer circularServicesDB.Close()478 if err := circularServicesDB.Set("VISB525", "Mordor circular"); err != nil {479 t.Fatal(err)480 }481 if err := circularServicesDB.Set("FMAN561", "Bree circular"); err != nil {482 t.Fatal(err)483 }484 in := Ingester{485 Logger: dlog.NewLogger([]dlog.LoggerOption{486 dlog.LoggerSetOutput(ioutil.Discard),487 }...),488 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{489 repository.RedisPoolDial(func() (redis.Conn, error) {490 return redis.Dial("tcp", departuresDB.Addr())491 }),492 }...),493 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{494 repository.RedisPoolDial(func() (redis.Conn, error) {495 return redis.Dial("tcp", localityNamesDB.Addr())496 }),497 }...),498 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{499 repository.RedisPoolDial(func() (redis.Conn, error) {500 return redis.Dial("tcp", stopsInAreaDB.Addr())501 }),502 }...),503 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{504 repository.RedisPoolDial(func() (redis.Conn, error) {505 return redis.Dial("tcp", circularServicesDB.Addr())506 }),507 }...),508 circularServices: make(map[string]*string),509 localityNames: make(map[string]*string),510 stopsInArea: make(map[string]*string),511 }512 event := buildSnsEvent(t, location1NewDeparture2, location1NewDeparture3, location1NewDeparture4, location2NewDeparture3, location2NewDeparture4, location2NewDeparture5, location2NewDeparture6)513 if err := in.Handler(event); err != nil {514 t.Error(err)515 return516 }517 departuresDB.CheckList(t, locationAtcocode, []string{518 string(location1NewDeparture2Expectation),519 string(location1NewDeparture3Expectation),520 string(location1NewDeparture4Expectation),521 }...)522 departuresDB.CheckList(t, extraLocationAtcocode, []string{523 string(location2NewDeparture3Expectation),524 string(location2NewDeparture4Expectation),525 string(location2NewDeparture5Expectation),526 string(location2NewDeparture6Expectation),527 }...)528 departuresDB.CheckList(t, stopAreaAtcocode, []string{529 string(location1NewDeparture2Expectation),530 string(location2NewDeparture3Expectation),531 string(location1NewDeparture3Expectation),532 string(location1NewDeparture4Expectation),533 string(location2NewDeparture4Expectation),534 string(location2NewDeparture5Expectation),535 string(location2NewDeparture6Expectation),536 }...)537 })538 t.Run("returns an error on departures connection failure", func(t *testing.T) {539 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "1m"), nil, locationAtcocode, nil, "1800WA12481", "Turning Circle", "534", "ANWE")540 localityNamesDB, err := miniredis.Run()541 if err != nil {542 t.Fatal(err)543 }544 defer localityNamesDB.Close()545 if err := localityNamesDB.Set("1800WA12481", "Hobbiton"); err != nil {546 t.Fatal(err)547 }548 departuresDB, err := miniredis.Run()549 if err != nil {550 t.Fatal(err)551 }552 defer departuresDB.Close()553 stopsInAreaDB, err := miniredis.Run()554 if err != nil {555 t.Fatal(err)556 }557 defer stopsInAreaDB.Close()558 circularServicesDB, err := miniredis.Run()559 if err != nil {560 t.Fatal(err)561 }562 defer circularServicesDB.Close()563 in := Ingester{564 Logger: dlog.NewLogger([]dlog.LoggerOption{565 dlog.LoggerSetOutput(ioutil.Discard),566 }...),567 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{568 repository.RedisPoolDial(func() (redis.Conn, error) {569 return redis.Dial("tcp", "")570 }),571 }...),572 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{573 repository.RedisPoolDial(func() (redis.Conn, error) {574 return redis.Dial("tcp", localityNamesDB.Addr())575 }),576 }...),577 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{578 repository.RedisPoolDial(func() (redis.Conn, error) {579 return redis.Dial("tcp", stopsInAreaDB.Addr())580 }),581 }...),582 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{583 repository.RedisPoolDial(func() (redis.Conn, error) {584 return redis.Dial("tcp", circularServicesDB.Addr())585 }),586 }...),587 circularServices: make(map[string]*string),588 localityNames: make(map[string]*string),589 stopsInArea: make(map[string]*string),590 }591 event := buildSnsEvent(t, newDeparture1)592 if err := in.Handler(event); err == nil {593 t.Error("Should return an error!")594 }595 })596 t.Run("returns an error on stops in area connection failure", func(t *testing.T) {597 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "1m"), nil, locationAtcocode, nil, "1800WA12481", "Turning Circle", "534", "ANWE")598 newDeparture1Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "1m"), nil, locationAtcocode, nil, "1800WA12481", "Hobbiton", "534", "ANWE")599 localityNamesDB, err := miniredis.Run()600 if err != nil {601 t.Fatal(err)602 }603 defer localityNamesDB.Close()604 if err := localityNamesDB.Set("1800WA12481", "Hobbiton"); err != nil {605 t.Fatal(err)606 }607 departuresDB, err := miniredis.Run()608 if err != nil {609 t.Fatal(err)610 }611 defer departuresDB.Close()612 if _, err := departuresDB.Push(locationAtcocode, []string{string(newDeparture1)}...); err != nil {613 t.Fatal(err)614 }615 stopsInAreaDB, err := miniredis.Run()616 if err != nil {617 t.Fatal(err)618 }619 defer stopsInAreaDB.Close()620 circularServicesDB, err := miniredis.Run()621 if err != nil {622 t.Fatal(err)623 }624 defer circularServicesDB.Close()625 in := Ingester{626 Logger: dlog.NewLogger([]dlog.LoggerOption{627 dlog.LoggerSetOutput(ioutil.Discard),628 }...),629 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{630 repository.RedisPoolDial(func() (redis.Conn, error) {631 return redis.Dial("tcp", departuresDB.Addr())632 }),633 }...),634 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{635 repository.RedisPoolDial(func() (redis.Conn, error) {636 return redis.Dial("tcp", localityNamesDB.Addr())637 }),638 }...),639 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{640 repository.RedisPoolDial(func() (redis.Conn, error) {641 return redis.Dial("tcp", "")642 }),643 }...),644 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{645 repository.RedisPoolDial(func() (redis.Conn, error) {646 return redis.Dial("tcp", circularServicesDB.Addr())647 }),648 }...),649 circularServices: make(map[string]*string),650 localityNames: make(map[string]*string),651 stopsInArea: make(map[string]*string),652 }653 event := buildSnsEvent(t, newDeparture1)654 if err := in.Handler(event); err == nil {655 t.Error("Should return an error!")656 }657 departuresDB.CheckList(t, locationAtcocode, []string{string(newDeparture1Expectation)}...)658 if _, err := departuresDB.List(stopAreaAtcocode); err == nil {659 t.Errorf("Expected error for %s", stopAreaAtcocode)660 }661 })662 t.Run("handles stops that are not in a stop area", func(t *testing.T) {663 cachedExpectedDepartureTime1 := test_helpers.AdjustTime(now, "-1m")664 cachedDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1234, test_helpers.AdjustTime(now, "-2m"), &cachedExpectedDepartureTime1, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")665 cachedExpectedDepartureTime2 := test_helpers.AdjustTime(now, "1m")666 cachedDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1235, test_helpers.AdjustTime(now, "-2m"), &cachedExpectedDepartureTime2, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")667 cachedDeparture3 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1236, test_helpers.AdjustTime(now, "-2m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Hobbiton", "534", "ANWE")668 cachedDeparture4 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "-3m"), 1237, test_helpers.AdjustTime(now, "2m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")669 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "-1m"), nil, locationAtcocode, &locationStand, "1800WA12481", "Turning Circle", "534", "ANWE")670 newDeparture2 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1239, test_helpers.AdjustTime(now, "3m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Hobbiton Interchange", "525", "VISB")671 newDeparture2Expectation := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1239, test_helpers.AdjustTime(now, "3m"), nil, locationAtcocode, &locationStand, locationAtcocode, "Mordor circular", "525", "VISB")672 localityNamesDB, err := miniredis.Run()673 if err != nil {674 t.Fatal(err)675 }676 defer localityNamesDB.Close()677 departuresDB, err := miniredis.Run()678 if err != nil {679 t.Fatal(err)680 }681 defer departuresDB.Close()682 if _, err := departuresDB.Push(locationAtcocode, []string{683 string(cachedDeparture1),684 string(cachedDeparture2),685 string(cachedDeparture3),686 string(cachedDeparture4),687 }...); err != nil {688 t.Fatal(err)689 }690 if _, err := departuresDB.Push(locationAtcocode, []string{string(newDeparture1)}...); err != nil {691 t.Fatal(err)692 }693 stopsInAreaDB, err := miniredis.Run()694 if err != nil {695 t.Fatal(err)696 }697 defer stopsInAreaDB.Close()698 circularServicesDB, err := miniredis.Run()699 if err != nil {700 t.Fatal(err)701 }702 defer circularServicesDB.Close()703 if err := circularServicesDB.Set("VISB525", "Mordor circular"); err != nil {704 t.Fatal(err)705 }706 in := Ingester{707 Logger: dlog.NewLogger([]dlog.LoggerOption{708 dlog.LoggerSetOutput(ioutil.Discard),709 }...),710 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{711 repository.RedisPoolDial(func() (redis.Conn, error) {712 return redis.Dial("tcp", departuresDB.Addr())713 }),714 }...),715 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{716 repository.RedisPoolDial(func() (redis.Conn, error) {717 return redis.Dial("tcp", localityNamesDB.Addr())718 }),719 }...),720 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{721 repository.RedisPoolDial(func() (redis.Conn, error) {722 return redis.Dial("tcp", stopsInAreaDB.Addr())723 }),724 }...),725 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{726 repository.RedisPoolDial(func() (redis.Conn, error) {727 return redis.Dial("tcp", circularServicesDB.Addr())728 }),729 }...),730 circularServices: make(map[string]*string),731 localityNames: make(map[string]*string),732 stopsInArea: make(map[string]*string),733 }734 event := buildSnsEvent(t, newDeparture1, newDeparture2)735 if err := in.Handler(event); err != nil {736 t.Error(err)737 return738 }739 departuresDB.CheckList(t, locationAtcocode, []string{740 string(cachedDeparture2),741 string(cachedDeparture4),742 string(newDeparture2Expectation),743 }...)744 })745 t.Run("returns an error on locality names connection failure", func(t *testing.T) {746 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "1m"), nil, locationAtcocode, nil, "1800WA12481", "Turning Circle", "534", "ANWE")747 localityNamesDB, err := miniredis.Run()748 if err != nil {749 t.Fatal(err)750 }751 defer localityNamesDB.Close()752 departuresDB, err := miniredis.Run()753 if err != nil {754 t.Fatal(err)755 }756 defer departuresDB.Close()757 stopsInAreaDB, err := miniredis.Run()758 if err != nil {759 t.Fatal(err)760 }761 defer stopsInAreaDB.Close()762 circularServicesDB, err := miniredis.Run()763 if err != nil {764 t.Fatal(err)765 }766 defer circularServicesDB.Close()767 in := Ingester{768 Logger: dlog.NewLogger([]dlog.LoggerOption{769 dlog.LoggerSetOutput(ioutil.Discard),770 }...),771 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{772 repository.RedisPoolDial(func() (redis.Conn, error) {773 return redis.Dial("tcp", departuresDB.Addr())774 }),775 }...),776 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{777 repository.RedisPoolDial(func() (redis.Conn, error) {778 return redis.Dial("tcp", "")779 }),780 }...),781 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{782 repository.RedisPoolDial(func() (redis.Conn, error) {783 return redis.Dial("tcp", stopsInAreaDB.Addr())784 }),785 }...),786 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{787 repository.RedisPoolDial(func() (redis.Conn, error) {788 return redis.Dial("tcp", circularServicesDB.Addr())789 }),790 }...),791 circularServices: make(map[string]*string),792 localityNames: make(map[string]*string),793 stopsInArea: make(map[string]*string),794 }795 event := buildSnsEvent(t, newDeparture1)796 if err := in.Handler(event); err == nil {797 t.Error("Should return an error!")798 }799 })800 t.Run("returns an error on circular services connection failure", func(t *testing.T) {801 newDeparture1 := buildJSONDeparture(t, test_helpers.AdjustTime(now, "0m"), 1238, test_helpers.AdjustTime(now, "1m"), nil, locationAtcocode, nil, "1800WA12481", "Turning Circle", "534", "ANWE")802 localityNamesDB, err := miniredis.Run()803 if err != nil {804 t.Fatal(err)805 }806 defer localityNamesDB.Close()807 departuresDB, err := miniredis.Run()808 if err != nil {809 t.Fatal(err)810 }811 defer departuresDB.Close()812 stopsInAreaDB, err := miniredis.Run()813 if err != nil {814 t.Fatal(err)815 }816 defer stopsInAreaDB.Close()817 circularServicesDB, err := miniredis.Run()818 if err != nil {819 t.Fatal(err)820 }821 defer circularServicesDB.Close()822 in := Ingester{823 Logger: dlog.NewLogger([]dlog.LoggerOption{824 dlog.LoggerSetOutput(ioutil.Discard),825 }...),826 DeparturesPool: repository.NewRedisPool([]repository.RedisPoolOption{827 repository.RedisPoolDial(func() (redis.Conn, error) {828 return redis.Dial("tcp", departuresDB.Addr())829 }),830 }...),831 LocalityNamesPool: repository.NewRedisPool([]repository.RedisPoolOption{832 repository.RedisPoolDial(func() (redis.Conn, error) {833 return redis.Dial("tcp", "")834 }),835 }...),836 StopsInAreaPool: repository.NewRedisPool([]repository.RedisPoolOption{837 repository.RedisPoolDial(func() (redis.Conn, error) {838 return redis.Dial("tcp", stopsInAreaDB.Addr())839 }),840 }...),841 CircularServicesPool: repository.NewRedisPool([]repository.RedisPoolOption{842 repository.RedisPoolDial(func() (redis.Conn, error) {843 return redis.Dial("tcp", "")844 }),845 }...),846 circularServices: make(map[string]*string),847 localityNames: make(map[string]*string),848 stopsInArea: make(map[string]*string),849 }850 event := buildSnsEvent(t, newDeparture1)...

Full Screen

Full Screen

optis_poller_test.go

Source:optis_poller_test.go Github

copy

Full Screen

...42 ms.PublishCallCount = ms.PublishCallCount + 143 return &ms.Output, nil44}45const (46 optisStopMonitoringRequestUrl = "http://foo.bar/"47 optisAPIKey = "abc123"48 busStationAtcocode = "1800BNIN"49 requestorRef = "OPTIS_TEST"50 previewInterval = "PT1H30M"51 maximumStopVisits = 5052 snsTopicArn = "arn:aws:sns:mars-north-8:123456789012:optis-departures"53)54var (55 now = time.Now()56 previewIntervalDuration, _ = duration.FromString(previewInterval)57 ErrorConditionSiriResponse = model.Siri{58 ServiceDelivery: model.ServiceDelivery{59 Status: false,60 ErrorCondition: model.ErrorCondition{61 Description: "Requestorref not subscribed to StopMonitoring single shot.",62 },63 },64 }65 InvalidAtcoCodeSiriResponse = model.Siri{66 ServiceDelivery: model.ServiceDelivery{67 Status: true,68 MoreData: false,69 StopMonitoringDelivery: model.StopMonitoringDelivery{70 Status: true,71 },72 },73 }74 StatusFalseSiriResponse = model.Siri{75 ServiceDelivery: model.ServiceDelivery{76 Status: false,77 },78 }79 HappyBusStationSiriResponse = model.Siri{80 ServiceDelivery: model.ServiceDelivery{81 Status: true,82 StopMonitoringDelivery: model.StopMonitoringDelivery{83 Status: true,84 MonitoredStopVisit: []model.MonitoredStopVisit{85 {86 RecordedAtTime: time.Now(),87 MonitoringRef: "1800BNIN0A1",88 MonitoredVehicleJourney: model.MonitoredVehicleJourney{89 LineRef: "1",90 DirectionRef: "inbound",91 FramedVehicleJourneyRef: model.FramedVehicleJourneyRef{92 DataFrameRef: "2019-05-09",93 DatedVehicleJourneyRef: "0001",94 },95 DestinationRef: "1800HN00011",96 DestinationName: "Hobbiton",97 OriginAimedDepartureTime: test_helpers.AdjustTime(now, "-20m"),98 DestinationAimedArrivalTime: test_helpers.AdjustTime(now, "1h30m"),99 MonitoredCall: model.MonitoredCall{100 StopPointRef: "1800BNIN0A1",101 AimedDepartureTime: test_helpers.AdjustTime(now, "3m8s"),102 ExpectedDepartureTime: test_helpers.AdjustTime(now, "59s"),103 },104 },105 Extensions: model.Extensions{106 NationalOperatorCode: "ANWE",107 },108 },109 {110 RecordedAtTime: time.Now(),111 MonitoringRef: "1800BNIN0B1",112 MonitoredVehicleJourney: model.MonitoredVehicleJourney{113 LineRef: "2",114 DirectionRef: "outbound",115 FramedVehicleJourneyRef: model.FramedVehicleJourneyRef{116 DataFrameRef: "2019-05-09",117 DatedVehicleJourneyRef: "0002",118 },119 DestinationRef: "1800MD00011",120 DestinationName: "Mordor",121 OriginAimedDepartureTime: test_helpers.AdjustTime(now, "-20m"),122 DestinationAimedArrivalTime: test_helpers.AdjustTime(now, "1h30m"),123 MonitoredCall: model.MonitoredCall{124 StopPointRef: "1800BNIN0B1",125 AimedDepartureTime: test_helpers.AdjustTime(now, "1m10s"),126 },127 },128 Extensions: model.Extensions{129 NationalOperatorCode: "ANWE",130 },131 },132 {133 RecordedAtTime: time.Now(),134 MonitoringRef: "1800BNIN0C1",135 MonitoredVehicleJourney: model.MonitoredVehicleJourney{136 LineRef: "3",137 DirectionRef: "outbound",138 FramedVehicleJourneyRef: model.FramedVehicleJourneyRef{139 DataFrameRef: "2019-05-09",140 DatedVehicleJourneyRef: "0003",141 },142 DestinationRef: "1800MT00011",143 DestinationName: "Minas Tirith",144 OriginAimedDepartureTime: test_helpers.AdjustTime(now, "-20m"),145 DestinationAimedArrivalTime: test_helpers.AdjustTime(now, "1h30m"),146 MonitoredCall: model.MonitoredCall{147 StopPointRef: "1800BNIN0C1",148 AimedDepartureTime: test_helpers.AdjustTime(now, "3m8s"),149 ExpectedDepartureTime: test_helpers.AdjustTime(now, "1m1s"),150 },151 },152 Extensions: model.Extensions{153 NationalOperatorCode: "ANWE",154 },155 },156 {157 RecordedAtTime: time.Now(),158 MonitoringRef: "1800BNIN0D1",159 MonitoredVehicleJourney: model.MonitoredVehicleJourney{160 LineRef: "4",161 DirectionRef: "inbound",162 FramedVehicleJourneyRef: model.FramedVehicleJourneyRef{163 DataFrameRef: "2019-05-09",164 DatedVehicleJourneyRef: "0004",165 },166 DestinationRef: "1800BR00011",167 DestinationName: "Bree",168 OriginAimedDepartureTime: test_helpers.AdjustTime(now, "-20m"),169 DestinationAimedArrivalTime: test_helpers.AdjustTime(now, "1h30m"),170 MonitoredCall: model.MonitoredCall{171 StopPointRef: "1800BNIN0D1",172 AimedDepartureTime: test_helpers.AdjustTime(now, "3m8s"),173 ExpectedDepartureTime: test_helpers.AdjustTime(now, "2m59s"),174 },175 },176 Extensions: model.Extensions{177 NationalOperatorCode: "ANWE",178 },179 },180 {181 RecordedAtTime: time.Now(),182 MonitoringRef: "1800BNIN0E1",183 MonitoredVehicleJourney: model.MonitoredVehicleJourney{184 LineRef: "5",185 DirectionRef: "inbound",186 FramedVehicleJourneyRef: model.FramedVehicleJourneyRef{187 DataFrameRef: "2019-05-09",188 DatedVehicleJourneyRef: "0005",189 },190 DestinationRef: "1800BR00021",191 OriginAimedDepartureTime: test_helpers.AdjustTime(now, "-20m"),192 DestinationAimedArrivalTime: test_helpers.AdjustTime(now, "1h30m"),193 MonitoredCall: model.MonitoredCall{194 StopPointRef: "1800BNIN0E1",195 AimedArrivalTime: test_helpers.AdjustTime(now, "3m8s"),196 ExpectedArrivalTime: test_helpers.AdjustTime(now, "3m8s"),197 },198 },199 Extensions: model.Extensions{200 NationalOperatorCode: "ANWE",201 },202 },203 {204 RecordedAtTime: time.Now(),205 MonitoringRef: "1800BNIN0F1",206 MonitoredVehicleJourney: model.MonitoredVehicleJourney{207 LineRef: "6",208 DirectionRef: "inbound",209 FramedVehicleJourneyRef: model.FramedVehicleJourneyRef{210 DataFrameRef: "2019-05-10",211 DatedVehicleJourneyRef: "0006",212 },213 DestinationRef: "1800BR00021",214 OriginAimedDepartureTime: time.Now().Add(24 * time.Hour).Truncate(24 * time.Hour).Add(10 * time.Hour),215 DestinationAimedArrivalTime: time.Now().Add(24 * time.Hour).Truncate(24 * time.Hour).Add(12 * time.Hour),216 MonitoredCall: model.MonitoredCall{217 StopPointRef: "1800BNIN0F1",218 AimedArrivalTime: time.Now().Add(24 * time.Hour).Truncate(24 * time.Hour).Add(12 * time.Hour),219 AimedDepartureTime: time.Now().Add(24 * time.Hour).Truncate(24 * time.Hour),220 },221 },222 Extensions: model.Extensions{223 NationalOperatorCode: "ANWE",224 },225 },226 {227 RecordedAtTime: time.Now(),228 MonitoringRef: "1800BNIN0G1",229 MonitoredVehicleJourney: model.MonitoredVehicleJourney{230 LineRef: "7",231 DirectionRef: "inbound",232 FramedVehicleJourneyRef: model.FramedVehicleJourneyRef{233 DataFrameRef: "2019-05-10",234 DatedVehicleJourneyRef: "0007",235 },236 DestinationRef: "1800BR00021",237 OriginAimedDepartureTime: test_helpers.AdjustTime(now, "-20m"),238 DestinationAimedArrivalTime: test_helpers.AdjustTime(now, "1h30m"),239 MonitoredCall: model.MonitoredCall{240 StopPointRef: "1800BNIN0B1",241 AimedDepartureTime: test_helpers.AdjustTime(now, "1m10s"),242 DepartureStatus: "cancelled",243 },244 },245 Extensions: model.Extensions{246 NationalOperatorCode: "ANWE",247 },248 },249 },250 },251 },252 }253)254func (mockOptisClient *MockOptisClient) Request(siriRequest string) (*model.Siri, int, error) {255 siriRequestXML := new(model.Siri)256 if err := xml.Unmarshal([]byte(siriRequest), &siriRequestXML); err != nil {257 return nil, http.StatusInternalServerError, err258 }259 switch true {260 case siriRequestXML.ServiceRequest.RequestorRef != requestorRef:261 return &ErrorConditionSiriResponse, http.StatusBadRequest, errors.New("Requestorref not subscribed to StopMonitoring single shot.")262 case siriRequestXML.ServiceRequest.StopMonitoringRequest.MaximumStopVisits != maximumStopVisits:263 return &StatusFalseSiriResponse, http.StatusBadRequest, errors.New("OPTIS returned an error")264 case siriRequestXML.ServiceRequest.StopMonitoringRequest.MonitoringRef == busStationAtcocode:265 return &HappyBusStationSiriResponse, http.StatusOK, nil266 default:267 return &InvalidAtcoCodeSiriResponse, http.StatusOK, nil268 }269}270func TestOptisPoller_Handler(t *testing.T) {271 defer leaktest.Check(t)()272 logger := dlog.NewLogger([]dlog.LoggerOption{273 dlog.LoggerSetOutput(ioutil.Discard),274 }...)275 t.Run("happy bus station path", func(t *testing.T) {276 busStation := BusStation{277 Atcocode: busStationAtcocode,278 }279 mockedOptisClient := &MockOptisClient{280 OptisURL: optisStopMonitoringRequestUrl,281 OptisAPIKey: optisAPIKey,282 }283 mockedSNSClient := &MockSNSClient{284 Output: sns.PublishOutput{285 MessageId: aws.String("ABC-123"),286 },287 T: t,288 }289 op := OptisPoller{290 Logger: logger,291 OptisClient: mockedOptisClient,292 OptisMaximumStopVisits: maximumStopVisits,293 OptisPreviewInterval: *previewIntervalDuration,294 OptisRequestorRef: requestorRef,295 SNSClient: mockedSNSClient,296 SNSTopicARN: aws.String(snsTopicArn),297 }298 expectation := sns.PublishInput{299 Message: aws.String(`{"departures":[` +300 `{"recordedAtTime":"` + now.Format(time.RFC3339) + `","journeyType":"` + string(model.Bus) + `","journeyRef":"1_inbound_2019-05-09_0001","aimedDepartureTime":"` + test_helpers.AdjustTime(now, "3m8s").Format(time.RFC3339) + `","expectedDepartureTime":"` + test_helpers.AdjustTime(now, "59s").Format(time.RFC3339) + `","locationAtcocode":"` + busStationAtcocode + `0A1","stand":"A","destinationAtcocode":"1800HN00011","destination":"Hobbiton","serviceNumber":"1","operatorCode":"ANWE"},` +301 `{"recordedAtTime":"` + now.Format(time.RFC3339) + `","journeyType":"` + string(model.Bus) + `","journeyRef":"2_outbound_2019-05-09_0002","aimedDepartureTime":"` + test_helpers.AdjustTime(now, "1m10s").Format(time.RFC3339) + `","locationAtcocode":"` + busStationAtcocode + `0B1","stand":"B","destinationAtcocode":"1800MD00011","destination":"Mordor","serviceNumber":"2","operatorCode":"ANWE"},` +302 `{"recordedAtTime":"` + now.Format(time.RFC3339) + `","journeyType":"` + string(model.Bus) + `","journeyRef":"3_outbound_2019-05-09_0003","aimedDepartureTime":"` + test_helpers.AdjustTime(now, "3m8s").Format(time.RFC3339) + `","expectedDepartureTime":"` + test_helpers.AdjustTime(now, "1m1s").Format(time.RFC3339) + `","locationAtcocode":"` + busStationAtcocode + `0C1","stand":"C","destinationAtcocode":"1800MT00011","destination":"Minas Tirith","serviceNumber":"3","operatorCode":"ANWE"},` +303 `{"recordedAtTime":"` + now.Format(time.RFC3339) + `","journeyType":"` + string(model.Bus) + `","journeyRef":"4_inbound_2019-05-09_0004","aimedDepartureTime":"` + test_helpers.AdjustTime(now, "3m8s").Format(time.RFC3339) + `","expectedDepartureTime":"` + test_helpers.AdjustTime(now, "2m59s").Format(time.RFC3339) + `","locationAtcocode":"` + busStationAtcocode + `0D1","stand":"D","destinationAtcocode":"1800BR00011","destination":"Bree","serviceNumber":"4","operatorCode":"ANWE"}` +304 `]}`),305 TopicArn: aws.String(snsTopicArn),306 }307 mockedSNSClient.SetPublishExpectation(expectation)308 if err := op.Handler(busStation); err != nil {309 t.Error(err)310 return311 }312 if mockedSNSClient.PublishCallCount != 1 {313 t.Error("SNS Publish should have been called once.")314 }315 })316 t.Run("bad request to OPTIS because of incorrect RequestorRef", func(t *testing.T) {317 busStation := BusStation{318 Atcocode: busStationAtcocode,319 }320 mockedOptisClient := &MockOptisClient{321 OptisURL: optisStopMonitoringRequestUrl,322 OptisAPIKey: optisAPIKey,323 }324 mockedSNSClient := &MockSNSClient{325 Output: sns.PublishOutput{326 MessageId: aws.String("ABC-123"),327 },328 T: t,329 }330 op := OptisPoller{331 Logger: logger,332 OptisClient: mockedOptisClient,333 OptisMaximumStopVisits: maximumStopVisits,334 OptisPreviewInterval: *previewIntervalDuration,335 OptisRequestorRef: "invalid",336 SNSClient: mockedSNSClient,337 SNSTopicARN: aws.String(snsTopicArn),338 }339 if err := op.Handler(busStation); err == nil {340 t.Error("Error should have been returned; OPTIS Requestor Ref not set")341 }342 if mockedSNSClient.PublishCallCount != 0 {343 t.Error("Publish should not be called if the request to OPTIS fails")344 }345 })346 t.Run("missing atcocode", func(t *testing.T) {347 busStation := BusStation{}348 mockedOptisClient := &MockOptisClient{349 OptisURL: optisStopMonitoringRequestUrl,350 OptisAPIKey: optisAPIKey,351 }352 mockedSNSClient := &MockSNSClient{353 Output: sns.PublishOutput{354 MessageId: aws.String("ABC-123"),355 },356 T: t,357 }358 op := OptisPoller{359 Logger: logger,360 OptisClient: mockedOptisClient,361 OptisMaximumStopVisits: maximumStopVisits,362 OptisPreviewInterval: *previewIntervalDuration,363 OptisRequestorRef: requestorRef,364 SNSClient: mockedSNSClient,365 SNSTopicARN: aws.String(snsTopicArn),366 }367 expectation := sns.PublishInput{368 Message: aws.String(`{"departures":null}`),369 TopicArn: aws.String(snsTopicArn),370 }371 mockedSNSClient.SetPublishExpectation(expectation)372 if err := op.Handler(busStation); err != nil {373 t.Error(err)374 return375 }376 if mockedSNSClient.PublishCallCount != 1 {377 t.Error("SNS Publish should have been called once.")378 }379 })380 t.Run("invalid atcocode", func(t *testing.T) {381 busStation := BusStation{382 Atcocode: "invalid",383 }384 mockedOptisClient := &MockOptisClient{385 OptisURL: optisStopMonitoringRequestUrl,386 OptisAPIKey: optisAPIKey,387 }388 mockedSNSClient := &MockSNSClient{389 Output: sns.PublishOutput{390 MessageId: aws.String("ABC-123"),391 },392 T: t,393 }394 op := OptisPoller{395 Logger: logger,396 OptisClient: mockedOptisClient,397 OptisMaximumStopVisits: maximumStopVisits,398 OptisPreviewInterval: *previewIntervalDuration,399 OptisRequestorRef: requestorRef,400 SNSClient: mockedSNSClient,401 SNSTopicARN: aws.String(snsTopicArn),402 }403 expectation := sns.PublishInput{404 Message: aws.String(`{"departures":null}`),405 TopicArn: aws.String(snsTopicArn),406 }407 mockedSNSClient.SetPublishExpectation(expectation)408 if err := op.Handler(busStation); err != nil {409 t.Error(err)410 return411 }...

Full Screen

Full Screen

watcher_test.go

Source:watcher_test.go Github

copy

Full Screen

...33 err := os.RemoveAll(path)34 if err != nil {35 log.Fatalf("Unable to remove %s. Error: %v", path, err)36 }37 watcher.Stop()38}39func commit(t *testing.T, path string) {40 test_helpers.PerformCmd(t, path, "git", "add", "--all")41 test_helpers.PerformCmd(t, path, "git", "commit", "-m", "Test")42}43func TestGitWatcher_Watch(t *testing.T) {44 var watcher, listener, path, channel = setup()45 defer cleanup(watcher, path)46 watcher.Watch(path, channel)47 assert.Equal(t, 0, len(listener.paths))48 test_helpers.WriteFile(t, path, "test.md", "Watch")49 time.Sleep(1 * time.Second)50 assert.Greater(t, len(listener.paths), 0)51 assert.Equal(t, path, listener.paths[0])...

Full Screen

Full Screen

Stop

Using AI Code Generation

copy

Full Screen

1func TestStop(t *testing.T) {2 if err := test_helpers.Stop(); err != nil {3 t.Fatal(err)4 }5}6func TestStop(t *testing.T) {7 if err := test_helpers.Stop(); err != nil {8 t.Fatal(err)9 }10}11func TestStop(t *testing.T) {12 if err := test_helpers.Stop(); err != nil {13 t.Fatal(err)14 }15}16func TestStop(t *testing.T) {17 if err := test_helpers.Stop(); err != nil {18 t.Fatal(err)19 }20}21func TestStop(t *testing.T) {22 if err := test_helpers.Stop(); err != nil {23 t.Fatal(err)24 }25}26func TestStop(t *testing.T) {27 if err := test_helpers.Stop(); err != nil {28 t.Fatal(err)29 }30}31func TestStop(t *testing.T) {32 if err := test_helpers.Stop(); err != nil {33 t.Fatal(err)34 }35}36func TestStop(t *testing.T) {37 if err := test_helpers.Stop(); err != nil {38 t.Fatal(err)39 }40}41func TestStop(t *testing.T) {42 if err := test_helpers.Stop(); err != nil {43 t.Fatal(err)44 }45}46func TestStop(t *testing.T) {47 if err := test_helpers.Stop(); err != nil {48 t.Fatal(err)49 }50}51func TestStop(t *testing.T) {52 if err := test_helpers.Stop(); err != nil {53 t.Fatal(err)54 }

Full Screen

Full Screen

Stop

Using AI Code Generation

copy

Full Screen

1import (2func TestStop(t *testing.T) {3 gomega.RegisterFailHandler(ginkgo.Fail)4 ginkgo.RunSpecs(t, "Stop Suite")5}6var _ = ginkgo.Describe("Stop", func() {7 var (8 ginkgo.BeforeEach(func() {9 pathToBinary, err = gexec.Build("github.com/onsi/gomega/test_helpers/test_binary")10 gomega.Expect(err).NotTo(gomega.HaveOccurred())11 })12 ginkgo.AfterEach(func() {13 gexec.CleanupBuildArtifacts()14 })15 ginkgo.It("should stop the program", func() {16 session, err = gexec.Start(gexec.Command(pathToBinary, "sleep", "2"), ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)17 gomega.Expect(err).NotTo(gomega.HaveOccurred())18 gomega.Eventually(session).Should(gexec.Exit(0))19 })20 ginkgo.It("should stop the program", func() {21 session, err = gexec.Start(gexec.Command(pathToBinary, "sleep", "2"), ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)22 gomega.Expect(err).NotTo(gomega.HaveOccurred())23 gomega.Eventually(session).Should(gexec.Exit(0))24 })25 ginkgo.It("should stop the program", func() {26 session, err = gexec.Start(gexec.Command(pathToBinary, "sleep", "2"), ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)27 gomega.Expect(err).NotTo(gomega.HaveOccurred())28 gomega.Eventually(session).Should(gexec.Exit(0))29 })30 ginkgo.It("should stop the program", func() {31 session, err = gexec.Start(gexec.Command(pathToBinary, "sleep", "2"), ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)32 gomega.Expect(err).NotTo(gomega.HaveOccurred())33 gomega.Eventually(session).Should(gexec.Exit(0))34 })35 ginkgo.It("should stop

Full Screen

Full Screen

Stop

Using AI Code Generation

copy

Full Screen

1import (2func TestStop(t *testing.T) {3 test_helpers.Stop(t)4}5import (6func TestStop(t *testing.T) {7 test_helpers.Stop(t)8}9import (10func TestStop(t *testing.T) {11 test_helpers.Stop(t)12}13import (14func TestStop(t *testing.T) {15 test_helpers.Stop(t)16}17import (18func TestStop(t *testing.T) {19 test_helpers.Stop(t)20}21import (22func TestStop(t *testing.T) {23 test_helpers.Stop(t)24}25import (26func TestStop(t *testing.T) {27 test_helpers.Stop(t)28}29import (30func TestStop(t *testing.T) {31 test_helpers.Stop(t)32}33import (34func TestStop(t *testing.T) {35 test_helpers.Stop(t)36}

Full Screen

Full Screen

Stop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 test_helpers.Stop()4}5import (6func main() {7 test_helpers.Wait()8}9import (10func main() {11 test_helpers.WaitStop()12}13import (14func main() {15 test_helpers.WaitStop()16}17import (18func main() {19 test_helpers.WaitStop()20}21import (22func main() {23 test_helpers.WaitStop()24}25import (26func main() {27 test_helpers.WaitStop()28}29import (

Full Screen

Full Screen

Stop

Using AI Code Generation

copy

Full Screen

1import (2func TestSomething(t *testing.T) {3 test_helpers.Stop("TestSomething")4}5func Stop(msg string) {6 fmt.Println(msg)7}

Full Screen

Full Screen

Stop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Starting the program")4 test_helpers.Stop(5)5 fmt.Println("Terminating the program")6}7import (8func Stop(sec int) {9 fmt.Println("Stopping the program for", sec, "seconds")10 time.Sleep(time.Duration(sec) * time.Second)11 fmt.Println("Program has been stopped for", sec, "seconds")12}13In addition to the above example, we can also use the Stop() method to stop the program execution for a specific time. For example, we can stop the program execution for 5:30 pm by passing the time value as an argument to the Stop() method. The Stop() method takes an integer value as an argument and stops the program execution for that many seconds

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful