Use go-cmp instead of reflect.DeepEqual to compare unit test results (#6343)

This commit is contained in:
Armel Soro
2022-11-24 13:24:32 +01:00
committed by GitHub
parent 1bfb116b74
commit 5660093167
73 changed files with 1198 additions and 1554 deletions

View File

@@ -5,11 +5,12 @@ import (
"fmt"
"io/ioutil"
"os"
"reflect"
"strconv"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/redhat-developer/odo/pkg/config"
envcontext "github.com/redhat-developer/odo/pkg/config/context"
@@ -71,9 +72,8 @@ func TestNew(t *testing.T) {
t.Errorf("expected test to fail, but it passed!")
}
}
if !reflect.DeepEqual(test.output, cfi) {
t.Errorf("expected output: %#v", test.output)
t.Errorf("actual output: %#v", cfi)
if diff := cmp.Diff(test.output, cfi); diff != "" {
t.Errorf("newPreferenceInfo() mismatch (-want +got):\n%s", diff)
}
})
}
@@ -614,8 +614,8 @@ func TestHandleWithoutRegistryExist(t *testing.T) {
t.Logf("Error message is %v", err)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Got: %v, want %v", got, tt.want)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("handleWithoutRegistryExist() mismatch (-want +got):\n%s", diff)
}
})
}
@@ -667,8 +667,8 @@ func TestHandleWithRegistryExist(t *testing.T) {
t.Logf("Error message is %v", err)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Got: %v, want: %v", got, tt.want)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("handleWithRegistryExist() mismatch (-want +got):\n%s", diff)
}
}
}