Skip to content

Commit

Permalink
Use deep.Equal
Browse files Browse the repository at this point in the history
  • Loading branch information
gfr10598 committed Dec 12, 2018
1 parent dab4dc2 commit 1c666b2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"strings"
"testing"
"time"

"github.com/go-test/deep"
"github.com/m-lab/annotation-service/api"
"github.com/m-lab/annotation-service/geolite2"
"github.com/m-lab/annotation-service/handler"
Expand Down Expand Up @@ -108,11 +108,11 @@ func TestValidateAndParse(t *testing.T) {
}
for _, test := range tests {
res, err := handler.ValidateAndParse(test.req)
if !reflect.DeepEqual(res, test.res) {
t.Errorf("Expected %+v, got %+v.", test.res, res)
if diff := deep.Equal(res, test.res); diff != nil {
t.Error(diff)
}
if !reflect.DeepEqual(err, test.err) {
t.Errorf("Expected %+v, got %+v.", test.err, err)
if diff := deep.Equal(err, test.err); diff != nil {
t.Error(diff)
}
}

Expand Down Expand Up @@ -171,9 +171,10 @@ func TestBatchValidateAndParse(t *testing.T) {
continue
}
res, err := handler.BatchValidateAndParse(jsonBuffer)
if !reflect.DeepEqual(res, test.res) {
t.Errorf("Test %d: Expected %+v, got %+v.", i, test.res, res)
if diff := deep.Equal(res, test.res); diff != nil {
t.Error(diff)
}
// TODO use deep.Equal for testing errors?
if err != nil && test.err == nil || err == nil && test.err != nil {
t.Errorf("Test %d: Expected %+v, got %+v.", i, test.err, err)
continue
Expand Down Expand Up @@ -279,8 +280,8 @@ func TestGetMetadataForSingleIP(t *testing.T) {
}
for _, test := range tests {
res, _ := handler.GetMetadataForSingleIP(test.req)
if !reflect.DeepEqual(res, test.res) {
t.Errorf("Expected %v, got %v", test.res, res)
if diff := deep.Equal(res, test.res); diff != nil {
t.Error(diff)
}
}
}

0 comments on commit 1c666b2

Please sign in to comment.