-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparcel_test.go
63 lines (58 loc) · 1.57 KB
/
parcel_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package parcel_test
import (
"fmt"
"testing"
parcel "dev.freespoke.com/go-package-tracking"
"dev.freespoke.com/go-package-tracking/internal"
"github.com/stretchr/testify/assert"
)
// Testing for all positive and negative test cases embedded in the shipping
// service json files.
func TestAllServices(t *testing.T) {
if len(internal.Services) == 0 {
t.Fatal("TestAllServices: No services loaded.")
}
for _, service := range internal.Services {
for _, test := range service.TestNumbers.Valid {
name := fmt.Sprintf("valid %s:%s", service.ID, test)
t.Run(name, func(t *testing.T) {
got, err := parcel.Track(test)
if err != nil {
t.Errorf("parcel.Track() error %v", err)
return
}
if len(got) == 0 {
t.Error("parcel.Track() expected a result. Got none.")
return
}
s := make([]string, 0)
for _, v := range got {
if v.Service == service.Name {
return
}
s = append(s, v.Service)
}
t.Errorf("parcel.Track() unexpected service. Wanted %s, got [%v]", service.Name, s)
})
}
for _, test := range service.TestNumbers.Invalid {
name := fmt.Sprintf("invalid %s:%s", service.ID, test)
t.Run(name, func(t *testing.T) {
got, err := parcel.Track(test)
if err != nil {
t.Errorf("parcel.Track() error %v", err)
return
}
for _, v := range got {
if v.Service == service.Name {
t.Errorf("parcelTrack() should not match service %s", service.Name)
return
}
}
})
}
}
}
func TestServices(t *testing.T) {
assert.EqualValues(t, parcel.Services(), internal.Services)
}