From 88b498f23ed6726a3da9a15051584b3a83bdaba2 Mon Sep 17 00:00:00 2001 From: Madhav Jivrajani Date: Wed, 15 Mar 2023 17:27:34 +0530 Subject: [PATCH] test/e2e: Improve kubectl subresource e2e test We now get structured output using jsonpath for the name and version fields of the node object and then compare the outputs. Signed-off-by: Madhav Jivrajani --- test/e2e/kubectl/kubectl.go | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/test/e2e/kubectl/kubectl.go b/test/e2e/kubectl/kubectl.go index c851cb48d57..fa2e30b1594 100644 --- a/test/e2e/kubectl/kubectl.go +++ b/test/e2e/kubectl/kubectl.go @@ -2048,26 +2048,19 @@ metadata: framework.ExpectNoError(err) gomega.Expect(nodes.Items).ToNot(gomega.BeEmpty()) node := nodes.Items[0] - ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s", node.Name)) - outBuiltIn := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name) - ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s --subresource=status", node.Name)) - outStatusSubresource := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name, "--subresource=status") // Avoid comparing values of fields that might end up - // changing between the two invocations of kubectl. - requiredOutput := [][]string{ - {"NAME"}, - {"STATUS"}, - {"ROLES"}, - {"AGE"}, - {"VERSION"}, - {node.Name}, // check for NAME - {""}, // avoid comparing STATUS - {""}, // avoid comparing ROLES - {""}, // avoid comparing AGE - {node.Status.NodeInfo.KubeletVersion}, // check for VERSION - } - checkOutput(outBuiltIn, requiredOutput) - checkOutput(outStatusSubresource, requiredOutput) + // changing between the two invocations of kubectl. We + // compare the name and version fields. + ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s", node.Name)) + outBuiltIn := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name, + "--output=jsonpath='{.metadata.name}{.status.nodeInfo.kubeletVersion}'", + ) + ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s --subresource=status", node.Name)) + outStatusSubresource := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name, + "--output=jsonpath='{.metadata.name}{.status.nodeInfo.kubeletVersion}'", + "--subresource=status", + ) + gomega.Expect(outBuiltIn).To(gomega.Equal(outStatusSubresource)) }) }) })