Skip to content

Commit 3510ae5

Browse files
authored
Merge pull request kubernetes#84843 from clarklee92/UseFrameworkExpectIn-e2e
Use framework.ExpectEqual() in unit test
2 parents 715b6af + 7ce1284 commit 3510ae5

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

test/e2e/framework/log_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var _ = ginkgo.Describe("log", func() {
5757
}()
5858
})
5959
ginkgo.It("asserts", func() {
60-
gomega.Expect(false).To(gomega.Equal(true), "false is never true")
60+
framework.ExpectEqual(false, true, "false is never true")
6161
})
6262
ginkgo.It("error", func() {
6363
err := errors.New("an error with a long, useless description")
@@ -68,7 +68,7 @@ var _ = ginkgo.Describe("log", func() {
6868
})
6969
ginkgo.AfterEach(func() {
7070
framework.Logf("after")
71-
gomega.Expect(true).To(gomega.Equal(false), "true is never false either")
71+
framework.ExpectEqual(true, false, "true is never false either")
7272
})
7373
})
7474

@@ -83,7 +83,6 @@ func TestFailureOutput(t *testing.T) {
8383
runTests(fakeT, reporter)
8484

8585
// Now check the output.
86-
g := gomega.NewGomegaWithT(t)
8786
actual := normalizeReport(*reporter)
8887

8988
// output from AfterEach
@@ -117,16 +116,16 @@ func TestFailureOutput(t *testing.T) {
117116
},
118117
}
119118
// Compare individual fields. Comparing the slices leads to unreadable error output when there is any mismatch.
120-
g.Expect(len(actual)).To(gomega.Equal(len(expected)), "%d entries in %v", len(expected), actual)
119+
framework.ExpectEqual(len(actual), len(expected), "%d entries in %v", len(expected), actual)
121120
for i, a := range actual {
122121
b := expected[i]
123-
g.Expect(a.name).To(gomega.Equal(b.name), "name in %d", i)
124-
g.Expect(a.output).To(gomega.Equal(b.output), "output in %d", i)
125-
g.Expect(a.failure).To(gomega.Equal(b.failure), "failure in %d", i)
122+
framework.ExpectEqual(a.name, b.name, "name in %d", i)
123+
framework.ExpectEqual(a.output, b.output, "output in %d", i)
124+
framework.ExpectEqual(a.failure, b.failure, "failure in %d", i)
126125
// There may be additional stack entries from the "testing" package at the
127126
// end. We ignore those in the comparison because the line number in them
128127
// varies.
129-
g.Expect(a.stack).To(gomega.Equal(b.stack), "stack in %d: %s", i, a.stack)
128+
framework.ExpectEqual(a.stack, b.stack, "stack in %d: %s", i, a.stack)
130129
}
131130
}
132131

test/e2e/framework/timer/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ go_test(
1515
name = "go_default_test",
1616
srcs = ["timer_test.go"],
1717
embed = [":go_default_library"],
18-
deps = ["//vendor/github.com/onsi/gomega:go_default_library"],
18+
deps = [
19+
"//test/e2e/framework:go_default_library",
20+
"//vendor/github.com/onsi/gomega:go_default_library",
21+
],
1922
)
2023

2124
filegroup(

test/e2e/framework/timer/timer_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"time"
2222

2323
"github.com/onsi/gomega"
24+
25+
"k8s.io/kubernetes/test/e2e/framework"
2426
)
2527

2628
var currentTime time.Time
@@ -64,9 +66,9 @@ func TestTimer(t *testing.T) {
6466
}
6567
]
6668
}`))
67-
gomega.Expect(timer.PrintHumanReadable()).To(gomega.Equal(`Phase 001-one: 5.5s so far
69+
framework.ExpectEqual(timer.PrintHumanReadable(), `Phase 001-one: 5.5s so far
6870
Phase 033-two: 3.5s
69-
`))
71+
`)
7072

7173
setCurrentTimeSinceEpoch(7*time.Second + 500*time.Millisecond)
7274
phaseOne.End()
@@ -86,7 +88,7 @@ Phase 033-two: 3.5s
8688
}
8789
]
8890
}`))
89-
gomega.Expect(timer.PrintHumanReadable()).To(gomega.Equal(`Phase 001-one: 6.5s
91+
framework.ExpectEqual(timer.PrintHumanReadable(), `Phase 001-one: 6.5s
9092
Phase 033-two: 3.5s
91-
`))
93+
`)
9294
}

0 commit comments

Comments
 (0)