remove deprecated framework.ExpectEqual

This commit is contained in:
carlory 2023-10-11 10:37:36 +08:00
parent bdcb73d6b3
commit 2c1836bc24
12 changed files with 58 additions and 65 deletions

View File

@ -293,13 +293,6 @@ func (f *FailureError) backtrace() {
// }
var ErrFailure error = FailureError{}
// ExpectEqual expects the specified two are the same, otherwise an exception raises
//
// Deprecated: use gomega.Expect().To(gomega.Equal())
func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{}) {
gomega.ExpectWithOffset(1, actual).To(gomega.Equal(extra), explain...)
}
// ExpectNotEqual expects the specified two are not the same, otherwise an exception raises
//
// Deprecated: use gomega.Expect().ToNot(gomega.Equal())

View File

@ -24,6 +24,7 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/reporters"
"github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -36,8 +37,7 @@ import (
// Be careful when moving it around or changing the import statements above.
// Here are some intentionally blank lines that can be removed to compensate
// for future additional import statements.
//
// This must be line #39.
// This must be line #40.
// This is included in a stack backtrace.
func failHelper(msg string) {
@ -50,7 +50,7 @@ var _ = ginkgo.Describe("log", func() {
})
ginkgo.AfterEach(func() {
framework.Logf("after")
framework.ExpectEqual(true, false, "true is never false either")
gomega.Expect(true).To(gomega.BeFalse(), "true is never false either")
})
ginkgo.It("fails", func() {
func() {
@ -58,14 +58,14 @@ var _ = ginkgo.Describe("log", func() {
}()
})
ginkgo.It("asserts", func() {
framework.ExpectEqual(false, true, "false is never true")
gomega.Expect(false).To(gomega.BeTrue(), "false is never true")
})
ginkgo.It("error", func() {
err := errors.New("an error with a long, useless description")
framework.ExpectNoError(err, "hard-coded error")
})
ginkgo.It("equal", func() {
framework.ExpectEqual(0, 1, "of course it's not equal...")
gomega.Expect(0).To(gomega.Equal(1), "of course it's not equal...")
})
ginkgo.It("fails with helper", func() {
failHelper("I'm failing with helper.")
@ -109,8 +109,7 @@ INFO: after
[FAILED] true is never false either
Expected
<bool>: true
to equal
<bool>: false
to be false
In [AfterEach] at: log_test.go:53 <time>
< Exit [AfterEach] log - log_test.go:51 <time>
`,
@ -123,8 +122,7 @@ In [AfterEach] at: log_test.go:53 <time>
Description: `[FAILED] false is never true
Expected
<bool>: false
to equal
<bool>: true
to be true
In [It] at: log_test.go:61 <time>
There were additional failures detected after the initial failure. These are visible in the timeline
@ -137,8 +135,7 @@ INFO: before
[FAILED] false is never true
Expected
<bool>: false
to equal
<bool>: true
to be true
In [It] at: log_test.go:61 <time>
< Exit [It] asserts - log_test.go:60 <time>
> Enter [AfterEach] log - log_test.go:51 <time>
@ -146,8 +143,7 @@ INFO: after
[FAILED] true is never false either
Expected
<bool>: true
to equal
<bool>: false
to be false
In [AfterEach] at: log_test.go:53 <time>
< Exit [AfterEach] log - log_test.go:51 <time>
`,
@ -181,8 +177,7 @@ INFO: after
[FAILED] true is never false either
Expected
<bool>: true
to equal
<bool>: false
to be false
In [AfterEach] at: log_test.go:53 <time>
< Exit [AfterEach] log - log_test.go:51 <time>
`,
@ -218,8 +213,7 @@ INFO: after
[FAILED] true is never false either
Expected
<bool>: true
to equal
<bool>: false
to be false
In [AfterEach] at: log_test.go:53 <time>
< Exit [AfterEach] log - log_test.go:51 <time>
`,
@ -247,8 +241,7 @@ INFO: after
[FAILED] true is never false either
Expected
<bool>: true
to equal
<bool>: false
to be false
In [AfterEach] at: log_test.go:53 <time>
< Exit [AfterEach] log - log_test.go:51 <time>
`,
@ -261,8 +254,7 @@ In [AfterEach] at: log_test.go:53 <time>
Description: `[FAILED] true is never false either
Expected
<bool>: true
to equal
<bool>: false
to be false
In [AfterEach] at: log_test.go:53 <time>
`,
},
@ -278,8 +270,7 @@ INFO: after
[FAILED] true is never false either
Expected
<bool>: true
to equal
<bool>: false
to be false
In [AfterEach] at: log_test.go:53 <time>
< Exit [AfterEach] log - log_test.go:51 <time>
`,

View File

@ -22,6 +22,7 @@ import (
"time"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -63,7 +64,7 @@ func ExpectNodeHasLabel(ctx context.Context, c clientset.Interface, nodeName str
ginkgo.By("verifying the node has the label " + labelKey + " " + labelValue)
node, err := c.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
framework.ExpectNoError(err)
framework.ExpectEqual(node.Labels[labelKey], labelValue)
gomega.Expect(node.Labels).To(gomega.HaveKeyWithValue(labelKey, labelValue))
}
// RemoveLabelOffNode is for cleaning up labels temporarily added to node,

View File

@ -20,6 +20,7 @@ import (
"context"
"fmt"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
@ -128,7 +129,7 @@ done`, testCmd)
// Verify Pod affinity colocated the Pods.
loader := getRunningLoaderPod(ctx, nsName, clientset)
framework.ExpectEqual(pod.Spec.NodeName, loader.Spec.NodeName)
gomega.Expect(pod.Spec.NodeName).To(gomega.Equal(loader.Spec.NodeName))
return pod
}

View File

@ -21,8 +21,6 @@ import (
"time"
"github.com/onsi/gomega"
"k8s.io/kubernetes/test/e2e/framework"
)
var currentTime time.Time
@ -66,9 +64,9 @@ func TestTimer(t *testing.T) {
}
]
}`))
framework.ExpectEqual(timer.PrintHumanReadable(), `Phase 001-one: 5.5s so far
gomega.Expect(timer.PrintHumanReadable()).To(gomega.Equal(`Phase 001-one: 5.5s so far
Phase 033-two: 3.5s
`)
`))
setCurrentTimeSinceEpoch(7*time.Second + 500*time.Millisecond)
phaseOne.End()
@ -88,7 +86,7 @@ Phase 033-two: 3.5s
}
]
}`))
framework.ExpectEqual(timer.PrintHumanReadable(), `Phase 001-one: 6.5s
gomega.Expect(timer.PrintHumanReadable()).To(gomega.Equal(`Phase 001-one: 6.5s
Phase 033-two: 3.5s
`)
`))
}

View File

@ -808,7 +808,7 @@ retriesLoop:
if errs.Len() > 0 {
Failf("Unexpected error(s): %v", strings.Join(errs.List(), "\n - "))
}
ExpectEqual(totalValidWatchEvents, len(expectedWatchEvents), "Error: there must be an equal amount of total valid watch events (%d) and expected watch events (%d)", totalValidWatchEvents, len(expectedWatchEvents))
gomega.Expect(expectedWatchEvents).To(gomega.HaveLen(totalValidWatchEvents), "Error: there must be an equal amount of total valid watch events (%d) and expected watch events (%d)", totalValidWatchEvents, len(expectedWatchEvents))
break retriesLoop
}
}

View File

@ -697,7 +697,7 @@ func VerifyExecInPodFail(f *framework.Framework, pod *v1.Pod, shExec string, exi
if err != nil {
if exiterr, ok := err.(clientexec.ExitError); ok {
actualExitCode := exiterr.ExitStatus()
framework.ExpectEqual(actualExitCode, exitCode,
gomega.Expect(actualExitCode).To(gomega.Equal(exitCode),
"%q should fail with exit code %d, but failed with exit code %d and error message %q\nstdout: %s\nstderr: %s",
shExec, exitCode, actualExitCode, exiterr, stdout, stderr)
} else {

View File

@ -94,7 +94,7 @@ var _ = SIGDescribe("Container Manager Misc [Serial]", func() {
ginkgo.It("Kubelet's oom-score-adj should be -999", func(ctx context.Context) {
kubeletPids, err := getPidsForProcess(kubeletProcessName, "")
framework.ExpectNoError(err, "failed to get list of kubelet pids")
framework.ExpectEqual(len(kubeletPids), 1, "expected only one kubelet process; found %d", len(kubeletPids))
gomega.Expect(kubeletPids).To(gomega.HaveLen(1), "expected only one kubelet process; found %d", len(kubeletPids))
gomega.Eventually(ctx, func() error {
return validateOOMScoreAdjSetting(kubeletPids[0], -999)
}, 5*time.Minute, 30*time.Second).Should(gomega.BeNil())

View File

@ -378,8 +378,8 @@ func runDensityBatchTest(ctx context.Context, f *framework.Framework, rc *Resour
)
for name, create := range createTimes {
watch, ok := watchTimes[name]
framework.ExpectEqual(ok, true)
watch := watchTimes[name]
gomega.Expect(watchTimes).To(gomega.HaveKey(name))
e2eLags = append(e2eLags,
e2emetrics.PodLatencyData{Name: name, Latency: watch.Time.Sub(create.Time)})
@ -513,12 +513,16 @@ func newInformerWatchPod(ctx context.Context, f *framework.Framework, mutex *syn
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
p, ok := obj.(*v1.Pod)
framework.ExpectEqual(ok, true)
if !ok {
framework.Failf("Failed to cast object %T to Pod", obj)
}
go checkPodRunning(p)
},
UpdateFunc: func(oldObj, newObj interface{}) {
p, ok := newObj.(*v1.Pod)
framework.ExpectEqual(ok, true)
if !ok {
framework.Failf("Failed to cast object %T to Pod", newObj)
}
go checkPodRunning(p)
},
},
@ -554,8 +558,8 @@ func createBatchPodSequential(ctx context.Context, f *framework.Framework, pods
}
for name, create := range createTimes {
watch, ok := watchTimes[name]
framework.ExpectEqual(ok, true)
watch := watchTimes[name]
gomega.Expect(watchTimes).To(gomega.HaveKey(name))
if !init {
if firstCreate.Time.After(create.Time) {
firstCreate = create
@ -635,8 +639,9 @@ func logAndVerifyLatency(ctx context.Context, batchLag time.Duration, e2eLags []
// check bactch pod creation latency
if podBatchStartupLimit > 0 {
framework.ExpectEqual(batchLag <= podBatchStartupLimit, true, "Batch creation startup time %v exceed limit %v",
batchLag, podBatchStartupLimit)
if batchLag > podBatchStartupLimit {
framework.Failf("Batch creation startup time %v exceed limit %v", batchLag, podBatchStartupLimit)
}
}
}
}

View File

@ -355,7 +355,7 @@ func getNode(c *clientset.Clientset) (*v1.Node, error) {
if nodes == nil {
return nil, fmt.Errorf("the node list is nil")
}
framework.ExpectEqual(len(nodes.Items) > 1, false, "the number of nodes is more than 1.")
gomega.Expect(len(nodes.Items)).To(gomega.BeNumerically("<=", 1), "the number of nodes is more than 1.")
if len(nodes.Items) == 0 {
return nil, fmt.Errorf("empty node list: %+v", nodes)
}

View File

@ -280,7 +280,7 @@ var _ = SIGDescribe("Memory Manager [Disruptive] [Serial] [Feature:MemoryManager
currentNUMANodeIDs, err := cpuset.Parse(strings.Trim(output, "\n"))
framework.ExpectNoError(err)
framework.ExpectEqual(numaNodeIDs, currentNUMANodeIDs.List())
gomega.Expect(numaNodeIDs).To(gomega.Equal(currentNUMANodeIDs.List()))
}
waitingForHugepages := func(ctx context.Context, hugepagesCount int) {
@ -394,16 +394,16 @@ var _ = SIGDescribe("Memory Manager [Disruptive] [Serial] [Feature:MemoryManager
framework.ExpectNoError(err)
stateAllocatableMemory := getAllocatableMemoryFromStateFile(stateData)
framework.ExpectEqual(len(resp.Memory), len(stateAllocatableMemory))
gomega.Expect(resp.Memory).To(gomega.HaveLen(len(stateAllocatableMemory)))
for _, containerMemory := range resp.Memory {
gomega.Expect(containerMemory.Topology).NotTo(gomega.BeNil())
framework.ExpectEqual(len(containerMemory.Topology.Nodes), 1)
gomega.Expect(containerMemory.Topology.Nodes).To(gomega.HaveLen(1))
gomega.Expect(containerMemory.Topology.Nodes[0]).NotTo(gomega.BeNil())
numaNodeID := int(containerMemory.Topology.Nodes[0].ID)
for _, numaStateMemory := range stateAllocatableMemory {
framework.ExpectEqual(len(numaStateMemory.NUMAAffinity), 1)
gomega.Expect(numaStateMemory.NUMAAffinity).To(gomega.HaveLen(1))
if numaNodeID != numaStateMemory.NUMAAffinity[0] {
continue
}

View File

@ -134,7 +134,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
})
framework.ExpectNoError(err)
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
list, err = e2epod.NewPodClient(f).List(ctx, metav1.ListOptions{
FieldSelector: nodeSelector,
@ -142,7 +142,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
if err != nil {
framework.Failf("Failed to start batch pod: %q", err)
}
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
for _, pod := range list.Items {
framework.Logf("Pod (%v/%v) status conditions: %q", pod.Namespace, pod.Name, &pod.Status.Conditions)
@ -168,7 +168,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
if err != nil {
return err
}
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
for _, pod := range list.Items {
if !isPodShutdown(&pod) {
@ -236,7 +236,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
FieldSelector: nodeSelector,
})
framework.ExpectNoError(err)
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
ctx, cancel := context.WithCancel(ctx)
defer cancel()
@ -286,7 +286,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
if err != nil {
return err
}
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
for _, pod := range list.Items {
if kubelettypes.IsCriticalPod(&pod) {
@ -313,7 +313,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
if err != nil {
return err
}
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
for _, pod := range list.Items {
if !isPodShutdown(&pod) {
@ -514,7 +514,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
FieldSelector: nodeSelector,
})
framework.ExpectNoError(err)
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
ginkgo.By("Verifying batch pods are running")
for _, pod := range list.Items {
@ -537,7 +537,7 @@ var _ = SIGDescribe("GracefulNodeShutdown [Serial] [NodeFeature:GracefulNodeShut
if err != nil {
return err
}
framework.ExpectEqual(len(list.Items), len(pods), "the number of pods is not as expected")
gomega.Expect(list.Items).To(gomega.HaveLen(len(pods)), "the number of pods is not as expected")
for _, pod := range list.Items {
shouldShutdown := false
for _, podName := range step {
@ -628,10 +628,14 @@ func getGracePeriodOverrideTestPod(name string, node string, gracePeriod int64,
kubelettypes.ConfigSourceAnnotationKey: kubelettypes.FileSource,
}
pod.Spec.PriorityClassName = priorityClassName
framework.ExpectEqual(kubelettypes.IsCriticalPod(pod), true, "pod should be a critical pod")
if !kubelettypes.IsCriticalPod(pod) {
framework.Failf("pod %q should be a critical pod", pod.Name)
}
} else {
pod.Spec.PriorityClassName = priorityClassName
framework.ExpectEqual(kubelettypes.IsCriticalPod(pod), false, "pod should not be a critical pod")
if kubelettypes.IsCriticalPod(pod) {
framework.Failf("pod %q should not be a critical pod", pod.Name)
}
}
return pod
}
@ -650,7 +654,7 @@ func getNodeReadyStatus(ctx context.Context, f *framework.Framework) bool {
nodeList, err := f.ClientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
framework.ExpectNoError(err)
// Assuming that there is only one node, because this is a node e2e test.
framework.ExpectEqual(len(nodeList.Items), 1)
gomega.Expect(nodeList.Items).To(gomega.HaveLen(1), "the number of nodes is not as expected")
return isNodeReady(&nodeList.Items[0])
}