Skip to content

Commit f2dc2d0

Browse files
authored
Fixed Broken Tests (#7)
* Add Go-Reference badge * Refactor Operator Struct Refactor Operator Struct To Reflect Recent Changes To The Reloadly API Add More Tests To Improve Coverage * Fix broken Tests * Fix broken Tests
1 parent 8fea241 commit f2dc2d0

File tree

1 file changed

+121
-24
lines changed

1 file changed

+121
-24
lines changed

airtime/operators_test.go

Lines changed: 121 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,64 +63,161 @@ func TestClient_GetOperatorsByISO(t *testing.T) {
6363
defer teardown()
6464

6565
mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
66-
rw.WriteHeader(http.StatusOK)
67-
data := reloadly.Operators{
68-
TotalPages: 5,
69-
Size: 20,
70-
}
71-
72-
json.NewEncoder(rw).Encode(data)
73-
66+
rw.WriteHeader(http.StatusInternalServerError)
7467
})
7568

76-
body, err := client.GetOperatorsByISO("011")
77-
if err != nil {
78-
t.Errorf("Expected error to be nil but got %q", err)
69+
body, err := client.GetOperatorsByISO("")
70+
71+
if err == nil {
72+
t.Errorf("Expected error but got nil")
7973
}
8074

81-
if body.Size != 20 {
82-
t.Errorf("Expected Size to be 20 but got %v", body.Size)
75+
if body != nil {
76+
t.Errorf("Expected body to be nil but got %v", body)
8377
}
8478
}
8579

86-
func TestClient_GetOperators(t *testing.T) {
80+
81+
func TestClient_GetOperatorsById(t *testing.T) {
8782
teardown := setup()
8883

8984
defer teardown()
9085

91-
mux.HandleFunc("/operators", func(rw http.ResponseWriter, req *http.Request) {
86+
mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
9287
rw.WriteHeader(http.StatusOK)
9388
data := reloadly.Operators{
94-
TotalPages: 5,
95-
Size: 20,
89+
Name: "testOperator",
9690
}
9791

9892
json.NewEncoder(rw).Encode(data)
9993

10094
})
10195

102-
body, err := client.GetOperators()
96+
body, err := client.GetOperatorsById(7)
10397
if err != nil {
10498
t.Errorf("Expected error to be nil but got %q", err)
10599
}
106100

107-
if body.Size != 20 {
108-
t.Errorf("Expected Size to be 20 but got %v", body.Size)
101+
if body.Name != "testOperator" {
102+
t.Errorf("Expected Size to be testOperator but got %v", body.Name)
109103
}
110104
}
111105

112-
func TestClient_GetOperatorsById(t *testing.T) {
106+
func TestClient_GetOperators(t *testing.T) {
113107
teardown := setup()
114108

115109
defer teardown()
116110

117-
mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
111+
mux.HandleFunc("/operators", func(rw http.ResponseWriter, req *http.Request) {
118112
rw.WriteHeader(http.StatusInternalServerError)
119-
120113
})
121114

122-
_, err := client.GetOperators()
115+
body, err := client.GetOperators()
116+
123117
if err == nil {
124118
t.Errorf("Expected error but got nil")
125119
}
120+
121+
if body != nil {
122+
t.Errorf("Expected body to be nil but got %v", body)
123+
}
124+
}
125+
126+
func TestAddSuggestedAmounts(t *testing.T) {
127+
cases := [] struct{
128+
SuggestedAmounts bool
129+
ExpectedSuggestedAmounts bool
130+
}{
131+
{
132+
SuggestedAmounts: false,
133+
ExpectedSuggestedAmounts: false,
134+
},
135+
{
136+
SuggestedAmounts: true,
137+
ExpectedSuggestedAmounts: true,
138+
},
139+
}
140+
141+
142+
143+
for _, c := range cases {
144+
res := reloadly.AddSuggestedAmounts(c.SuggestedAmounts)
145+
o := &reloadly.OperatorOpts{}
146+
res(o)
147+
148+
if res != nil{
149+
if c.ExpectedSuggestedAmounts != o.SuggestedAmounts {
150+
t.Fatalf("Expected SuggestedAmounts to be %t but got %t", c.SuggestedAmounts, o.SuggestedAmounts)
151+
}
152+
153+
}
154+
155+
156+
}
157+
}
158+
159+
func TestAddBundles(t *testing.T) {
160+
cases := [] struct{
161+
IncludeBundles bool
162+
ExpectedIncludeBundles bool
163+
}{
164+
{
165+
IncludeBundles: false,
166+
ExpectedIncludeBundles: false,
167+
},
168+
{
169+
IncludeBundles: true,
170+
ExpectedIncludeBundles: true,
171+
},
172+
}
173+
174+
175+
176+
for _, c := range cases {
177+
res := reloadly.AddBundles(c.IncludeBundles)
178+
o := &reloadly.OperatorOpts{}
179+
res(o)
180+
181+
if res != nil{
182+
if c.ExpectedIncludeBundles != o.IncludeBundles {
183+
t.Fatalf("Expected SuggestedAmounts to be %t but got %t", c.IncludeBundles, o.IncludeBundles)
184+
}
185+
186+
}
187+
188+
189+
}
190+
}
191+
192+
func TestAddData(t *testing.T) {
193+
cases := [] struct{
194+
IncludeData bool
195+
ExpectedIncludeData bool
196+
}{
197+
{
198+
IncludeData: false,
199+
ExpectedIncludeData: false,
200+
},
201+
{
202+
IncludeData: true,
203+
ExpectedIncludeData: true,
204+
},
205+
}
206+
207+
208+
209+
for _, c := range cases {
210+
res := reloadly.AddData(c.IncludeData)
211+
o := &reloadly.OperatorOpts{}
212+
res(o)
213+
214+
if res != nil{
215+
if c.IncludeData != o.IncludeData {
216+
t.Fatalf("Expected SuggestedAmounts to be %t but got %t", c.IncludeData, o.IncludeData)
217+
}
218+
219+
}
220+
221+
222+
}
126223
}

0 commit comments

Comments
 (0)