Skip to content

Commit

Permalink
refactor: build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoral2 committed Jun 9, 2023
1 parent 62af3dc commit ea04540
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 52 deletions.
15 changes: 6 additions & 9 deletions tests/acceptance/Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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} \
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/core/service/assert/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/core/service/assert/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
4 changes: 2 additions & 2 deletions tests/acceptance/core/service/customflag/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions tests/acceptance/core/service/template/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand All @@ -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")
}
4 changes: 1 addition & 3 deletions tests/acceptance/core/service/template/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/core/testcase/upgradecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
31 changes: 4 additions & 27 deletions tests/acceptance/shared/aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package shared
import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand All @@ -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)
}
Expand Down

0 comments on commit ea04540

Please sign in to comment.