From 0a7c02ce9046c59071277ad6091d7b1f1218f2e6 Mon Sep 17 00:00:00 2001 From: Adrian Riobo Lorenzo Date: Mon, 20 May 2024 16:04:06 +0200 Subject: [PATCH] [qe] ensure all crc start commands set the bundle if it is passed through the params integration tests offers a parameter to setup a custom bundle. Previous code made use of the custom bundle on some of the start commands but missed to use it on others. As so the tests end failing due to bundle missmatch versions. This commit refactor the method used to test the setup and start commands making sure if custom bundle parameter is passed it is used always Signed-off-by: Adrian Riobo Lorenzo --- test/integration/podman_test.go | 17 +++++++--- test/integration/proxy_test.go | 28 ++++++++-------- test/integration/resize_test.go | 53 ++++++++++++++++++------------ test/integration/utilities_test.go | 24 ++++++++++++++ 4 files changed, 83 insertions(+), 39 deletions(-) diff --git a/test/integration/podman_test.go b/test/integration/podman_test.go index a5487f2dce..9bf44a4d8f 100644 --- a/test/integration/podman_test.go +++ b/test/integration/podman_test.go @@ -32,11 +32,16 @@ var _ = Describe("podman-remote", Serial, Ordered, Label("microshift-preset"), f }) It("setup CRC", func() { - Expect(RunCRCExpectSuccess("setup")).To(ContainSubstring("Your system is correctly setup for using CRC")) + Expect( + crcSuccess("setup")). + To(ContainSubstring("Your system is correctly setup for using CRC")) }) It("start CRC", func() { - Expect(RunCRCExpectSuccess("start", "-p", pullSecretPath)).To(ContainSubstring("Started the MicroShift cluster")) + // default values: "--memory", "10752", "--cpus", "4", "disk-size", "31" + Expect( + crcSuccess("start", "-p", pullSecretPath)). + To(ContainSubstring("Started the MicroShift cluster")) }) It("podman-env", func() { @@ -79,11 +84,15 @@ var _ = Describe("podman-remote", Serial, Ordered, Label("microshift-preset"), f }) It("cleanup CRC", func() { - Expect(RunCRCExpectSuccess("cleanup")).To(MatchRegexp("Cleanup finished")) + Expect( + crcSuccess("cleanup")). + To(MatchRegexp("Cleanup finished")) }) It("unset preset in config", func() { - Expect(RunCRCExpectSuccess("config", "unset", "preset")).To(ContainSubstring("Successfully unset configuration property 'preset'")) + Expect( + crcSuccess("config", "unset", "preset")). + To(ContainSubstring("Successfully unset configuration property 'preset'")) }) }) }) diff --git a/test/integration/proxy_test.go b/test/integration/proxy_test.go index 749d58d715..1088a7684b 100644 --- a/test/integration/proxy_test.go +++ b/test/integration/proxy_test.go @@ -5,7 +5,7 @@ import ( "os/exec" "runtime" - crcCmd "github.com/crc-org/crc/v2/test/extended/crc/cmd" + crc "github.com/crc-org/crc/v2/test/extended/crc/cmd" "github.com/crc-org/crc/v2/test/extended/util" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -59,24 +59,20 @@ var _ = Describe("", Serial, Ordered, Label("openshift-preset", "goproxy"), func }) It("setup CRC", func() { - if bundlePath == "" { - Expect(RunCRCExpectSuccess("setup")).To(ContainSubstring("Your system is correctly setup for using CRC")) - } else { - Expect(RunCRCExpectSuccess("setup", "-b", bundlePath)).To(ContainSubstring("Your system is correctly setup for using CRC")) - } + Expect( + crcSuccess("setup")). + To(ContainSubstring("Your system is correctly setup for using CRC")) }) It("start CRC", func() { // default values: "--memory", "10752", "--cpus", "4", "disk-size", "31" - if bundlePath == "" { - Expect(RunCRCExpectSuccess("start", "-p", pullSecretPath)).To(ContainSubstring("Started the OpenShift cluster")) - } else { - Expect(RunCRCExpectSuccess("start", "-b", bundlePath, "-p", pullSecretPath)).To(ContainSubstring("Started the OpenShift cluster")) - } + Expect( + crcSuccess("start", "-p", pullSecretPath)). + To(ContainSubstring("Started the OpenShift cluster")) }) It("wait for cluster in Running state", func() { - err := crcCmd.WaitForClusterInState("running") + err := crc.WaitForClusterInState("running") Expect(err).NotTo(HaveOccurred()) }) @@ -100,11 +96,15 @@ var _ = Describe("", Serial, Ordered, Label("openshift-preset", "goproxy"), func }) It("stop CRC", func() { - Expect(RunCRCExpectSuccess("stop", "-f")).To(MatchRegexp("[Ss]topped the instance")) + Expect( + crcSuccess("stop", "-f")). + To(MatchRegexp("[Ss]topped the instance")) }) It("cleanup CRC", func() { - Expect(RunCRCExpectSuccess("cleanup")).To(MatchRegexp("Cleanup finished")) + Expect( + crcSuccess("cleanup")). + To(MatchRegexp("Cleanup finished")) }) }) diff --git a/test/integration/resize_test.go b/test/integration/resize_test.go index 113afebb85..bba224a770 100644 --- a/test/integration/resize_test.go +++ b/test/integration/resize_test.go @@ -26,20 +26,15 @@ var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Ordered, Label Describe("use default values", Serial, Ordered, func() { It("setup CRC", func() { - if bundlePath == "" { - Expect(RunCRCExpectSuccess("setup")).To(ContainSubstring("Your system is correctly setup for using CRC")) - } else { - Expect(RunCRCExpectSuccess("setup", "-b", bundlePath)).To(ContainSubstring("Your system is correctly setup for using CRC")) - } + Expect( + crcSuccess("setup")). + To(ContainSubstring("Your system is correctly setup for using CRC")) }) It("start CRC", func() { - // default values: "--memory", "10752", "--cpus", "4", "disk-size", "31" - if bundlePath == "" { - Expect(RunCRCExpectSuccess("start", "--memory", "12000", "--cpus", "5", "--disk-size", "40", "-p", pullSecretPath)).To(ContainSubstring("Started the OpenShift cluster")) - } else { - Expect(RunCRCExpectSuccess("start", "--memory", "12000", "--cpus", "5", "--disk-size", "40", "-b", bundlePath, "-p", pullSecretPath)).To(ContainSubstring("Started the OpenShift cluster")) - } + Expect( + crcSuccess("start", "--memory", "12000", "--cpus", "5", "--disk-size", "40", "-p", pullSecretPath)). + To(ContainSubstring("Started the OpenShift cluster")) }) It("login to cluster using crc-admin context", func() { @@ -81,7 +76,9 @@ var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Ordered, Label }) It("stop CRC", func() { - Expect(RunCRCExpectSuccess("stop", "-f")).To(MatchRegexp("[Ss]topped the instance")) + Expect( + crcSuccess("stop", "-f")). + To(MatchRegexp("[Ss]topped the instance")) }) }) @@ -89,7 +86,9 @@ var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Ordered, Label Describe("use custom values", Serial, Ordered, func() { It("start CRC", func() { - Expect(RunCRCExpectSuccess("start", "--memory", "13000", "--cpus", "6", "--disk-size", "50")).To(ContainSubstring("Started the OpenShift cluster")) + Expect( + crcSuccess("start", "--memory", "13000", "--cpus", "6", "--disk-size", "50")). + To(ContainSubstring("Started the OpenShift cluster")) }) It("check VM's memory size", func() { @@ -112,34 +111,46 @@ var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Ordered, Label }) It("stop CRC", func() { - Expect(RunCRCExpectSuccess("stop", "-f")).To(MatchRegexp("[Ss]topped the instance")) + Expect( + crcSuccess("stop", "-f")). + To(MatchRegexp("[Ss]topped the instance")) }) }) Describe("use flawed values", Serial, Ordered, func() { It("start CRC with sub-minimum memory", func() { // less than min = 10752 - Expect(RunCRCExpectFail("start", "--memory", "9000")).To(ContainSubstring("requires memory in MiB >= 10752")) + Expect( + crcFails("start", "--memory", "9000")). + To(ContainSubstring("requires memory in MiB >= 10752")) }) It("start CRC with sub-minimum cpus", func() { // fewer than min - Expect(RunCRCExpectFail("start", "--cpus", "3")).To(ContainSubstring("requires CPUs >= 4")) + Expect( + crcFails("start", "--cpus", "3")). + To(ContainSubstring("requires CPUs >= 4")) }) It("start CRC with smaller disk", func() { // bigger than default && smaller than current + diskSizeOutput := "current disk image capacity is bigger than the requested size" if runtime.GOOS == "windows" { - Expect(RunCRCExpectFail("start", "--disk-size", "35")).To(ContainSubstring("Failed to set disk size to")) - } else { - Expect(RunCRCExpectFail("start", "--disk-size", "35")).To(ContainSubstring("current disk image capacity is bigger than the requested size")) + diskSizeOutput = "Failed to set disk size to" } + Expect( + crcFails("start", "--disk-size", "35")). + To(ContainSubstring(diskSizeOutput)) }) It("start CRC with sub-minimum disk", func() { // smaller than min = default = 31GiB - Expect(RunCRCExpectFail("start", "--disk-size", "30")).To(ContainSubstring("requires disk size in GiB >= 31")) // TODO: message should be different on macOS! + Expect( + crcFails("start", "--disk-size", "30")). + To(ContainSubstring("requires disk size in GiB >= 31")) }) }) Describe("use default values again", Serial, Ordered, func() { It("start CRC", func() { - Expect(RunCRCExpectSuccess("start")).To(ContainSubstring("Started the OpenShift cluster")) // default values: "--memory", "10752", "--cpus", "4", "disk-size", "31" + Expect( + crcSuccess("start")). + To(ContainSubstring("Started the OpenShift cluster")) }) It("check VM's memory size", func() { diff --git a/test/integration/utilities_test.go b/test/integration/utilities_test.go index 8541bffe91..1c9825e960 100644 --- a/test/integration/utilities_test.go +++ b/test/integration/utilities_test.go @@ -89,3 +89,27 @@ func RunCRCExpectFail(args ...string) (string, error) { return stderr, nil } + +// Helper function to run crc setup or start commands expecting success +func crcSuccess(op string, args ...string) string { + return RunCRCExpectSuccess( + crcCmd(op, args...)...) +} + +// Helper function to run crc setup or start commands expecting fails +func crcFails(op string, args ...string) string { + output, _ := RunCRCExpectFail( + crcCmd(op, args...)...) + return output +} + +// Helper function to add custom parameters if required +func crcCmd(op string, args ...string) []string { + cmd := []string{op} + if op == "start" || op == "setup" { + if len(bundlePath) > 0 { + cmd = append(cmd, "-b", bundlePath) + } + } + return append(cmd, args...) +}