service_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package tracking
  2. import (
  3. "testing"
  4. "github.com/longjoy/micro-go-course/section19/cargo/mock"
  5. shipping "github.com/longjoy/micro-go-course/section19/cargo/model"
  6. )
  7. func TestTrack(t *testing.T) {
  8. var cargos mock.CargoRepository
  9. cargos.FindFn = func(id shipping.TrackingID) (*shipping.Cargo, error) {
  10. return shipping.NewCargo("FTL456", shipping.RouteSpecification{
  11. Origin: shipping.AUMEL,
  12. Destination: shipping.SESTO,
  13. }), nil
  14. }
  15. var events mock.HandlingEventRepository
  16. events.QueryHandlingHistoryFn = func(id shipping.TrackingID) shipping.HandlingHistory {
  17. return shipping.HandlingHistory{}
  18. }
  19. s := NewService(&cargos, &events)
  20. c, err := s.Track("FTL456")
  21. if err != nil {
  22. t.Fatal(err)
  23. }
  24. if c.TrackingID != "FTL456" {
  25. t.Errorf("c.TrackingID = %v; want = %v", c.TrackingID, "FTL456")
  26. }
  27. if c.Origin != "AUMEL" {
  28. t.Errorf("c.Origin = %v; want = %v", c.Destination, "AUMEL")
  29. }
  30. if c.Destination != "SESTO" {
  31. t.Errorf("c.Destination = %v; want = %v", c.Destination, "SESTO")
  32. }
  33. if c.StatusText != shipping.NotReceived.String() {
  34. t.Errorf("c.StatusText = %v; want = %v", c.StatusText, shipping.NotReceived.String())
  35. }
  36. }