distro/test: use cmp.Diff rather than reflect.DeepEqual

This gives us more readable output. Both because it gives just a
diff, rather than the whole object as a string, but also as it
captures differences between the objects that thir string
representation does not.

In particular, if a field is an interface I, and T implements I,
then an object of type T and a pointer to the same object can both
be assigned to a variable of type I. Either way, the JSON
representation is the same, but the objects (correctly) do not
compare equal.

This is a pain to debug.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-03-14 16:54:33 +01:00
parent 538a16bf27
commit 0f2b8e597e

View file

@ -3,7 +3,6 @@ package distro_test
import (
"encoding/json"
"io/ioutil"
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
@ -73,11 +72,8 @@ func TestDistro_Manifest(t *testing.T) {
return
}
if tt.Manifest != nil {
if !reflect.DeepEqual(got, tt.Manifest) {
// Without this the "difference" is just a list of pointers.
gotJson, _ := json.Marshal(got)
fileJson, _ := json.Marshal(tt.Manifest)
t.Errorf("d.Pipeline() =\n%v,\nwant =\n%v", string(gotJson), string(fileJson))
if diff := cmp.Diff(got, tt.Manifest); diff != "" {
t.Errorf("d.Manifest() different from expected: %v", diff)
}
}
})