Replace apimachinery diff.StringDiff with cmp
I forced failures of most of these tests and verified readability Kubernetes-commit: 97bab44cae3857710bfb072d233e654784082ee3
This commit is contained in:
parent
3b35899e28
commit
a431fc3d05
|
|
@ -27,12 +27,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||||
"k8s.io/cli-runtime/pkg/resource"
|
"k8s.io/cli-runtime/pkg/resource"
|
||||||
|
|
@ -124,7 +124,7 @@ func TestEdit(t *testing.T) {
|
||||||
// Convenience to allow recapturing the input and persisting it here
|
// Convenience to allow recapturing the input and persisting it here
|
||||||
os.WriteFile(inputFile, body, os.FileMode(0644))
|
os.WriteFile(inputFile, body, os.FileMode(0644))
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
|
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, cmp.Diff(string(body), string(expectedInput)))
|
||||||
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
|
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,7 @@ func TestEdit(t *testing.T) {
|
||||||
// Convenience to allow recapturing the input and persisting it here
|
// Convenience to allow recapturing the input and persisting it here
|
||||||
os.WriteFile(inputFile, body, os.FileMode(0644))
|
os.WriteFile(inputFile, body, os.FileMode(0644))
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput)))
|
t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, cmp.Diff(string(body), string(expectedInput)))
|
||||||
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
|
t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||||
batchv1 "k8s.io/api/batch/v1"
|
batchv1 "k8s.io/api/batch/v1"
|
||||||
|
|
@ -36,7 +37,6 @@ import (
|
||||||
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
|
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||||
"k8s.io/cli-runtime/pkg/resource"
|
"k8s.io/cli-runtime/pkg/resource"
|
||||||
|
|
@ -1497,7 +1497,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
if e, a := expected, buf.String(); e != a {
|
if e, a := expected, buf.String(); e != a {
|
||||||
t.Errorf("did not match: %v", diff.StringDiff(e, a))
|
t.Errorf("did not match:\n%v", cmp.Diff(e, a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFormatterWrite(t *testing.T) {
|
func TestFormatterWrite(t *testing.T) {
|
||||||
|
|
@ -113,7 +113,7 @@ fringilla velit.
|
||||||
`
|
`
|
||||||
|
|
||||||
if buf.String() != want {
|
if buf.String() != want {
|
||||||
t.Errorf("Diff:\n%s", diff.StringDiff(buf.String(), want))
|
t.Errorf("Diff:\n%s", cmp.Diff(buf.String(), want))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue