Merge pull request #84843 from clarklee92/UseFrameworkExpectIn-e2e

Use framework.ExpectEqual() in unit test
This commit is contained in:
Kubernetes Prow Robot 2019-11-07 17:39:02 -08:00 committed by GitHub
commit 3510ae5233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View File

@ -57,7 +57,7 @@ var _ = ginkgo.Describe("log", func() {
}()
})
ginkgo.It("asserts", func() {
gomega.Expect(false).To(gomega.Equal(true), "false is never true")
framework.ExpectEqual(false, true, "false is never true")
})
ginkgo.It("error", func() {
err := errors.New("an error with a long, useless description")
@ -68,7 +68,7 @@ var _ = ginkgo.Describe("log", func() {
})
ginkgo.AfterEach(func() {
framework.Logf("after")
gomega.Expect(true).To(gomega.Equal(false), "true is never false either")
framework.ExpectEqual(true, false, "true is never false either")
})
})
@ -83,7 +83,6 @@ func TestFailureOutput(t *testing.T) {
runTests(fakeT, reporter)
// Now check the output.
g := gomega.NewGomegaWithT(t)
actual := normalizeReport(*reporter)
// output from AfterEach
@ -117,16 +116,16 @@ func TestFailureOutput(t *testing.T) {
},
}
// Compare individual fields. Comparing the slices leads to unreadable error output when there is any mismatch.
g.Expect(len(actual)).To(gomega.Equal(len(expected)), "%d entries in %v", len(expected), actual)
framework.ExpectEqual(len(actual), len(expected), "%d entries in %v", len(expected), actual)
for i, a := range actual {
b := expected[i]
g.Expect(a.name).To(gomega.Equal(b.name), "name in %d", i)
g.Expect(a.output).To(gomega.Equal(b.output), "output in %d", i)
g.Expect(a.failure).To(gomega.Equal(b.failure), "failure in %d", i)
framework.ExpectEqual(a.name, b.name, "name in %d", i)
framework.ExpectEqual(a.output, b.output, "output in %d", i)
framework.ExpectEqual(a.failure, b.failure, "failure in %d", i)
// There may be additional stack entries from the "testing" package at the
// end. We ignore those in the comparison because the line number in them
// varies.
g.Expect(a.stack).To(gomega.Equal(b.stack), "stack in %d: %s", i, a.stack)
framework.ExpectEqual(a.stack, b.stack, "stack in %d: %s", i, a.stack)
}
}

View File

@ -15,7 +15,10 @@ go_test(
name = "go_default_test",
srcs = ["timer_test.go"],
embed = [":go_default_library"],
deps = ["//vendor/github.com/onsi/gomega:go_default_library"],
deps = [
"//test/e2e/framework:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
],
)
filegroup(

View File

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