Skip to content

Commit

Permalink
Fixed Broken Tests (#7)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ghvstcode committed May 19, 2021
1 parent 8fea241 commit f2dc2d0
Showing 1 changed file with 121 additions and 24 deletions.
145 changes: 121 additions & 24 deletions airtime/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,64 +63,161 @@ func TestClient_GetOperatorsByISO(t *testing.T) {
defer teardown()

mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
data := reloadly.Operators{
TotalPages: 5,
Size: 20,
}

json.NewEncoder(rw).Encode(data)

rw.WriteHeader(http.StatusInternalServerError)
})

body, err := client.GetOperatorsByISO("011")
if err != nil {
t.Errorf("Expected error to be nil but got %q", err)
body, err := client.GetOperatorsByISO("")

if err == nil {
t.Errorf("Expected error but got nil")
}

if body.Size != 20 {
t.Errorf("Expected Size to be 20 but got %v", body.Size)
if body != nil {
t.Errorf("Expected body to be nil but got %v", body)
}
}

func TestClient_GetOperators(t *testing.T) {

func TestClient_GetOperatorsById(t *testing.T) {
teardown := setup()

defer teardown()

mux.HandleFunc("/operators", func(rw http.ResponseWriter, req *http.Request) {
mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
data := reloadly.Operators{
TotalPages: 5,
Size: 20,
Name: "testOperator",
}

json.NewEncoder(rw).Encode(data)

})

body, err := client.GetOperators()
body, err := client.GetOperatorsById(7)
if err != nil {
t.Errorf("Expected error to be nil but got %q", err)
}

if body.Size != 20 {
t.Errorf("Expected Size to be 20 but got %v", body.Size)
if body.Name != "testOperator" {
t.Errorf("Expected Size to be testOperator but got %v", body.Name)
}
}

func TestClient_GetOperatorsById(t *testing.T) {
func TestClient_GetOperators(t *testing.T) {
teardown := setup()

defer teardown()

mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
mux.HandleFunc("/operators", func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusInternalServerError)

})

_, err := client.GetOperators()
body, err := client.GetOperators()

if err == nil {
t.Errorf("Expected error but got nil")
}

if body != nil {
t.Errorf("Expected body to be nil but got %v", body)
}
}

func TestAddSuggestedAmounts(t *testing.T) {
cases := [] struct{
SuggestedAmounts bool
ExpectedSuggestedAmounts bool
}{
{
SuggestedAmounts: false,
ExpectedSuggestedAmounts: false,
},
{
SuggestedAmounts: true,
ExpectedSuggestedAmounts: true,
},
}



for _, c := range cases {
res := reloadly.AddSuggestedAmounts(c.SuggestedAmounts)
o := &reloadly.OperatorOpts{}
res(o)

if res != nil{
if c.ExpectedSuggestedAmounts != o.SuggestedAmounts {
t.Fatalf("Expected SuggestedAmounts to be %t but got %t", c.SuggestedAmounts, o.SuggestedAmounts)
}

}


}
}

func TestAddBundles(t *testing.T) {
cases := [] struct{
IncludeBundles bool
ExpectedIncludeBundles bool
}{
{
IncludeBundles: false,
ExpectedIncludeBundles: false,
},
{
IncludeBundles: true,
ExpectedIncludeBundles: true,
},
}



for _, c := range cases {
res := reloadly.AddBundles(c.IncludeBundles)
o := &reloadly.OperatorOpts{}
res(o)

if res != nil{
if c.ExpectedIncludeBundles != o.IncludeBundles {
t.Fatalf("Expected SuggestedAmounts to be %t but got %t", c.IncludeBundles, o.IncludeBundles)
}

}


}
}

func TestAddData(t *testing.T) {
cases := [] struct{
IncludeData bool
ExpectedIncludeData bool
}{
{
IncludeData: false,
ExpectedIncludeData: false,
},
{
IncludeData: true,
ExpectedIncludeData: true,
},
}



for _, c := range cases {
res := reloadly.AddData(c.IncludeData)
o := &reloadly.OperatorOpts{}
res(o)

if res != nil{
if c.IncludeData != o.IncludeData {
t.Fatalf("Expected SuggestedAmounts to be %t but got %t", c.IncludeData, o.IncludeData)
}

}


}
}

0 comments on commit f2dc2d0

Please sign in to comment.