diff --git a/tests/acceptance/Makefile b/tests/acceptance/Makefile index 461b2e96403..5360995a7cf 100644 --- a/tests/acceptance/Makefile +++ b/tests/acceptance/Makefile @@ -1,14 +1,12 @@ -##========================= Acceptance Tests =========================# include ./config.mk TAGNAME ?= default test-env-up: @cd ../.. && docker build . -q -f ./tests/acceptance/scripts/Dockerfile.build -t rke2-automated-${TAGNAME} -# -d .PHONY: test-run test-run: - docker run --name rke2-automated-test-${IMGNAME} -t \ + @docker run --name rke2-automated-test-${IMGNAME} -t \ -e AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \ -e AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \ -v ${ACCESS_KEY_LOCAL}:/go/src/github.com/rancher/rke2/tests/acceptance/modules/config/.ssh/aws_key.pem \ @@ -26,11 +24,11 @@ test-run: -expectedValueUpgradedNode "${VALUENODEUPGRADED}" -cmdHost "${CMDHOST}" -expectedValueHost "${VALUEHOST}" \ -expectedValueUpgradedHost "${VALUEHOSTUPGRADED}" -installUpgradeFlag "${INSTALLTYPE}" -testCase "${TESTCASE}" \ -deployWorkload "${DEPLOYWORKLOAD}"; \ - -description "${DESCRIPTION}"; \ elif [ "${TESTTAG}" = "coredns" ]; then \ go test -timeout=45m -v -tags=coredns ./versionbump/... -expectedValueNode "${VALUENODE}" \ -expectedValueUpgradedNode "${VALUENODEUPGRADED}" -expectedValueHost "${VALUEHOST}" \ - -expectedValueUpgradedHost "${VALUEHOSTUPGRADED}" -installUpgradeFlag "${INSTALLTYPE}"; \ + -expectedValueUpgradedHost "${VALUEHOSTUPGRADED}" -installUpgradeFlag "${INSTALLTYPE}" -testCase "${TESTCASE}" \ + -deployWorkload "${DEPLOYWORKLOAD}"; \ elif [ "${TESTTAG}" = "runc" ]; then \ go test -timeout=45m -v -tags=runc ./versionbump/... \ -expectedValueNode ${VALUENODE} \ @@ -93,16 +91,15 @@ test-version-runc: @go test -timeout=45m -v -tags=runc ./entrypoint/versionbump/... \ -expectedValueNode ${VALUENODE} \ -expectedValueUpgradedNode ${VALUENODEUPGRADED} \ - -installUpgradeFlag ${INSTALLTYPE} \ - + -installUpgradeFlag ${INSTALLTYPE} .PHONY: test-version-coredns test-version-coredns: - @go test -timeout=45m -v -tags=coredns ./entrypoint/versionbump/... \ + go test -timeout=45m -v -tags=coredns ./entrypoint/versionbump/... \ -expectedValueHost ${VALUEHOST} \ -expectedValueUpgradedHost ${VALUEHOSTUPGRADED} \ - -installUpgradeFlag ${INSTALLTYPE} \ + -installUpgradeFlag ${INSTALLTYPE} .PHONY: test-version-bump diff --git a/tests/acceptance/core/service/assert/host.go b/tests/acceptance/core/service/assert/host.go index 85706a5803c..9cbf71aac60 100644 --- a/tests/acceptance/core/service/assert/host.go +++ b/tests/acceptance/core/service/assert/host.go @@ -26,7 +26,7 @@ func CheckComponentCmdHost(cmd string, asserts ...string) { if !strings.Contains(res, assert) { return fmt.Errorf("expected substring %q not found in result %q", assert, res) } - fmt.Println("Result:", res+"Matched with assert:", assert) + fmt.Println("Result:", res+"\nMatched with assert:", assert) } return nil }, "420s", "5s").Should(Succeed()) diff --git a/tests/acceptance/core/service/assert/node.go b/tests/acceptance/core/service/assert/node.go index 4ebbbcf3928..3d19bcce86c 100644 --- a/tests/acceptance/core/service/assert/node.go +++ b/tests/acceptance/core/service/assert/node.go @@ -63,6 +63,6 @@ func CheckComponentCmdNode(cmd, assert, ip string) { } g.Expect(res).Should(ContainSubstring(assert)) - fmt.Println("Result:", res+"Matched with assert:", assert) + fmt.Println("Result:", res+"\nMatched with assert:", assert) }, "420s", "3s").Should(Succeed()) } diff --git a/tests/acceptance/core/service/customflag/model.go b/tests/acceptance/core/service/customflag/model.go index aab09daed6d..45b6835a961 100644 --- a/tests/acceptance/core/service/customflag/model.go +++ b/tests/acceptance/core/service/customflag/model.go @@ -29,7 +29,7 @@ type InstallTypeValueFlag struct { // TestConfigFlag is a customflag type that can be used to parse the test case argument type TestConfigFlag struct { - TestFuncName string + TestFuncName *string TestFunc TestCaseFlagType DeployWorkload bool } @@ -71,7 +71,7 @@ func (t *TestConfigFlag) Set(value string) error { return fmt.Errorf("invalid test case customflag format") } - t.TestFuncName = parts[0] + t.TestFuncName = &parts[0] if len(parts) > 1 { deployWorkload, err := strconv.ParseBool(parts[1]) if err != nil { diff --git a/tests/acceptance/core/service/template/helper.go b/tests/acceptance/core/service/template/helper.go index 50521d76129..c6282e5d614 100644 --- a/tests/acceptance/core/service/template/helper.go +++ b/tests/acceptance/core/service/template/helper.go @@ -44,7 +44,7 @@ func checkVersion(v VersionTestTemplate) error { len(ips)*(len(v.TestCombination.RunOnHost)+len(v.TestCombination.RunOnNode)), ) - processTestCombination(errorChanList, ips, *v.TestCombination) + processTestCombination(errorChanList, &wg, ips, *v.TestCombination) wg.Wait() close(errorChanList) @@ -82,8 +82,8 @@ func getIPs() (ips []string, err error) { } // GetTestCase returns the test case based on the name to be used as customflag. -func GetTestCase(name string) (TestCase, error) { - if name == "" { +func GetTestCase(name *string) (TestCase, error) { + if name == nil { return func(deployWorkload bool) {}, nil } @@ -96,9 +96,9 @@ func GetTestCase(name string) (TestCase, error) { "TestCoredns": testcase.TestCoredns, } - if test, ok := testCase[name]; ok { + if test, ok := testCase[*name]; ok { return test, nil + } else { + return nil, fmt.Errorf("invalid test case name") } - - return nil, fmt.Errorf("invalid test case name") } diff --git a/tests/acceptance/core/service/template/processor.go b/tests/acceptance/core/service/template/processor.go index 4265a5c9a56..4fa40f9dc2b 100644 --- a/tests/acceptance/core/service/template/processor.go +++ b/tests/acceptance/core/service/template/processor.go @@ -12,9 +12,7 @@ import ( // processTestCombination runs the tests per ips using CmdOnNode and CmdOnHost validation // it will spawn a go routine per ip -func processTestCombination(resultChan chan error, ips []string, testCombination RunCmd) { - var wg sync.WaitGroup - +func processTestCombination(resultChan chan error, wg *sync.WaitGroup, ips []string, testCombination RunCmd) { for _, ip := range ips { if testCombination.RunOnHost != nil { for _, test := range testCombination.RunOnHost { diff --git a/tests/acceptance/core/testcase/upgradecluster.go b/tests/acceptance/core/testcase/upgradecluster.go index f3a7c99ddec..676efc86bf2 100644 --- a/tests/acceptance/core/testcase/upgradecluster.go +++ b/tests/acceptance/core/testcase/upgradecluster.go @@ -32,8 +32,8 @@ func TestUpgradeClusterSUC(version string) error { ) Expect(err).NotTo(HaveOccurred()) - originalFilePath := shared.BasePath() + "/fixtures/workloads" + "/upgrade-plan.yaml" - newFilePath := shared.BasePath() + "/fixtures/workloads" + "/plan.yaml" + originalFilePath := shared.BasePath() + "/acceptance/workloads" + "/upgrade-plan.yaml" + newFilePath := shared.BasePath() + "/acceptance/workloads" + "/plan.yaml" content, err := os.ReadFile(originalFilePath) if err != nil { diff --git a/tests/acceptance/scripts/build.sh b/tests/acceptance/scripts/build.sh index 85759015703..607ac07de44 100755 --- a/tests/acceptance/scripts/build.sh +++ b/tests/acceptance/scripts/build.sh @@ -14,7 +14,7 @@ fi count=0 while [[ 3 -gt $count ]]; do - docker build . -f tests/rke2tf/shared/scripts/Dockerfile.build -t rke2-tf-"${TRIM_JOB_NAME}""${BUILD_NUMBER}" + docker build . -f tests/acceptance/scripts/Dockerfile.build -t rke2-test-"${TRIM_JOB_NAME}""${BUILD_NUMBER}" if [[ $? -eq 0 ]]; then break; fi count=$(($count + 1)) diff --git a/tests/acceptance/shared/aux.go b/tests/acceptance/shared/aux.go index eb1abb89e2d..a6d1b577d09 100644 --- a/tests/acceptance/shared/aux.go +++ b/tests/acceptance/shared/aux.go @@ -3,7 +3,6 @@ package shared import ( "bytes" "fmt" - "io" "os" "os/exec" "path/filepath" @@ -19,35 +18,13 @@ func RunCommandHost(cmds ...string) (string, error) { return "", fmt.Errorf("cmd should not be empty") } - var output bytes.Buffer + var output, errOut bytes.Buffer for _, cmd := range cmds { c := exec.Command("bash", "-c", cmd) - stdoutPipe, err := c.StdoutPipe() - if err != nil { - return "", err - } - stderrPipe, err := c.StderrPipe() - if err != nil { - return "", err - } - - err = c.Start() - if err != nil { - return "", err - } - - _, err = io.Copy(&output, stdoutPipe) - if err != nil { - return "", err - } - - _, err = io.Copy(&output, stderrPipe) - if err != nil { - return "", err - } - - err = c.Wait() + c.Stdout = &output + c.Stderr = &errOut + err := c.Run() if err != nil { return output.String(), fmt.Errorf("executing command: %s: %w", cmd, err) }