Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: use gomega.Expect instead of framework.ExpectEqual in kubectl #117963

Merged
merged 1 commit into from May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions test/e2e/kubectl/kubectl.go
Expand Up @@ -433,7 +433,7 @@ var _ = SIGDescribe("Kubectl client", func() {
veryLongData[i] = 'a'
}
execOutput = e2ekubectl.RunKubectlOrDie(ns, "exec", podRunningTimeoutArg, simplePodName, "--", "echo", string(veryLongData))
framework.ExpectEqual(string(veryLongData), strings.TrimSpace(execOutput), "Unexpected kubectl exec output")
gomega.Expect(string(veryLongData)).To(gomega.Equal(strings.TrimSpace(execOutput)), "Unexpected kubectl exec output")

ginkgo.By("executing a command in the container with noninteractive stdin")
execOutput = e2ekubectl.NewKubectlCommand(ns, "exec", "-i", podRunningTimeoutArg, simplePodName, "--", "cat").
Expand Down Expand Up @@ -544,7 +544,7 @@ var _ = SIGDescribe("Kubectl client", func() {
if !ok {
framework.Failf("Got unexpected error type, expected uexec.ExitError, got %T: %v", err, err)
}
framework.ExpectEqual(ee.ExitStatus(), 42)
gomega.Expect(ee.ExitStatus()).To(gomega.Equal(42))
humblec marked this conversation as resolved.
Show resolved Hide resolved
})

ginkgo.It("should support port-forward", func(ctx context.Context) {
Expand Down Expand Up @@ -671,15 +671,15 @@ metadata:
ginkgo.By("trying to use kubectl with invalid token")
_, err = e2eoutput.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --token=invalid --v=7 2>&1")
framework.Logf("got err %v", err)
framework.ExpectError(err)
gomega.Expect(err).To(gomega.HaveOccurred())
gomega.Expect(err).To(gomega.ContainSubstring("Using in-cluster namespace"))
gomega.Expect(err).To(gomega.ContainSubstring("Using in-cluster configuration"))
gomega.Expect(err).To(gomega.ContainSubstring("Response Status: 401 Unauthorized"))

ginkgo.By("trying to use kubectl with invalid server")
_, err = e2eoutput.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --server=invalid --v=6 2>&1")
framework.Logf("got err %v", err)
framework.ExpectError(err)
gomega.Expect(err).To(gomega.HaveOccurred())
gomega.Expect(err).To(gomega.ContainSubstring("Unable to connect to the server"))
gomega.Expect(err).To(gomega.ContainSubstring("GET http://invalid/api"))

Expand Down Expand Up @@ -710,7 +710,7 @@ metadata:
if !ok {
framework.Failf("Got unexpected error type, expected uexec.ExitError, got %T: %v", err, err)
}
framework.ExpectEqual(ee.ExitStatus(), 42)
gomega.Expect(ee.ExitStatus()).To(gomega.Equal(42))
})

ginkgo.It("[Slow] running a failing command without --restart=Never", func(ctx context.Context) {
Expand Down Expand Up @@ -1164,15 +1164,16 @@ metadata:
time.Sleep(10 * time.Second)

schema := schemaForGVK(schema.GroupVersionKind{Group: crd.Crd.Spec.Group, Version: crd.Crd.Spec.Versions[0].Name, Kind: crd.Crd.Spec.Names.Kind})
framework.ExpectNotEqual(schema, nil, "retrieving a schema for the crd")
gomega.Expect(schema).ToNot(gomega.BeNil(), "retrieving a schema for the crd")

meta := fmt.Sprintf(metaPattern, crd.Crd.Spec.Names.Kind, crd.Crd.Spec.Group, crd.Crd.Spec.Versions[0].Name, "test-cr")

// XPreserveUnknownFields is defined on the root of the schema so unknown fields within the spec
// are still considered invalid
invalidArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}],"extraProperty":"arbitrary-value"}}`, meta)
err = createApplyCustomResource(invalidArbitraryCR, f.Namespace.Name, "test-cr", crd)
framework.ExpectError(err, "creating custom resource")
gomega.Expect(err).To(gomega.HaveOccurred(), "creating custom resource")

if !strings.Contains(err.Error(), `unknown field "spec.extraProperty"`) {
framework.Failf("incorrect error from createApplyCustomResource: %v", err)
}
Expand Down Expand Up @@ -1215,7 +1216,7 @@ metadata:
ginkgo.By("attempting to create a CR with unknown metadata fields at the root level")
gvk := schema.GroupVersionKind{Group: testCRD.Crd.Spec.Group, Version: testCRD.Crd.Spec.Versions[0].Name, Kind: testCRD.Crd.Spec.Names.Kind}
schema := schemaForGVK(gvk)
framework.ExpectNotEqual(schema, nil, "retrieving a schema for the crd")
gomega.Expect(schema).ToNot(gomega.BeNil(), "retrieving a schema for the crd")
embeddedCRPattern := `

{%s,
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/kubectl/logs.go
Expand Up @@ -126,19 +126,19 @@ var _ = SIGDescribe("Kubectl logs", func() {
out := e2ekubectl.RunKubectlOrDie(ns, "logs", podName, containerName, "--tail=1")
framework.Logf("got output %q", out)
gomega.Expect(out).NotTo(gomega.BeEmpty())
framework.ExpectEqual(len(lines(out)), 1)
gomega.Expect(lines(out)).To(gomega.HaveLen(1))

ginkgo.By("limiting log bytes")
out = e2ekubectl.RunKubectlOrDie(ns, "logs", podName, containerName, "--limit-bytes=1")
framework.Logf("got output %q", out)
framework.ExpectEqual(len(lines(out)), 1)
framework.ExpectEqual(len(out), 1)
gomega.Expect(lines(out)).To(gomega.HaveLen(1))
gomega.Expect(out).To(gomega.HaveLen(1))

ginkgo.By("exposing timestamps")
out = e2ekubectl.RunKubectlOrDie(ns, "logs", podName, containerName, "--tail=1", "--timestamps")
framework.Logf("got output %q", out)
l := lines(out)
framework.ExpectEqual(len(l), 1)
gomega.Expect(l).To(gomega.HaveLen(1))
words := strings.Split(l[0], " ")
gomega.Expect(len(words)).To(gomega.BeNumerically(">", 1))
if _, err := time.Parse(time.RFC3339Nano, words[0]); err != nil {
Expand Down Expand Up @@ -192,18 +192,18 @@ var _ = SIGDescribe("Kubectl logs", func() {
out := e2ekubectl.RunKubectlOrDie(ns, "logs", podName, "-c", "container-1")
framework.Logf("got output %q", out)
gomega.Expect(out).NotTo(gomega.BeEmpty())
framework.ExpectEqual(len(lines(out)), 10)
gomega.Expect(lines(out)).To(gomega.HaveLen(10))

ginkgo.By("log all containers log lines")
out = e2ekubectl.RunKubectlOrDie(ns, "logs", podName, "--all-containers")
framework.Logf("got output %q", out)
gomega.Expect(out).NotTo(gomega.BeEmpty())
framework.ExpectEqual(len(lines(out)), 30)
gomega.Expect(lines(out)).To(gomega.HaveLen(30))

ginkgo.By("default container logs")
out = e2ekubectl.RunKubectlOrDie(ns, "logs", podName)
framework.Logf("got output %q", out)
framework.ExpectEqual(len(lines(out)), 20)
gomega.Expect(lines(out)).To(gomega.HaveLen(20))
})
})
})
Expand Down