Browse Source

Trying deep for testing

Piotr Czajkowski 3 years ago
parent
commit
b7ab8eebb3
3 changed files with 13 additions and 4 deletions
  1. 5 0
      go.mod
  2. 2 0
      go.sum
  3. 6 4
      rest_test.go

+ 5 - 0
go.mod

@@ -0,0 +1,5 @@
+module rest
+
+go 1.14
+
+require github.com/go-test/deep v1.0.6

+ 2 - 0
go.sum

@@ -0,0 +1,2 @@
+github.com/go-test/deep v1.0.6 h1:UHSEyLZUwX9Qoi99vVwvewiMC8mM2bf7XEM2nqvzEn8=
+github.com/go-test/deep v1.0.6/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=

+ 6 - 4
rest_test.go

@@ -6,6 +6,8 @@ import (
 	"net/http"
 	"net/http/httptest"
 	"testing"
+
+	"github.com/go-test/deep"
 )
 
 type Something struct {
@@ -25,8 +27,8 @@ func TestJSONDecoder(t *testing.T) {
 		t.Error(err)
 	}
 
-	if expected.First != result.First || expected.Second != result.Second {
-		t.Errorf("Wrong result: %v", result)
+	if diff := deep.Equal(expected, result); diff != nil {
+		t.Errorf("Wrong result: %v", diff)
 	}
 }
 
@@ -42,8 +44,8 @@ func TestJSONDecoderBadJSON(t *testing.T) {
 		t.Error("There should be an error")
 	}
 
-	if expected.First == result.First || expected.Second == result.Second {
-		t.Errorf("There should be an error on decoding, %v", result)
+	if diff := deep.Equal(expected, result); diff == nil {
+		t.Errorf("Structures shouldn't match, %v", diff)
 	}
 }