From ecaec27e97da46497ec67a2a2d5babf0162cea4c Mon Sep 17 00:00:00 2001 From: lilyLuLiu Date: Wed, 29 May 2024 10:54:57 +0800 Subject: [PATCH] [qe] change integration get parmeter way --- Makefile | 8 ++-- images/build-integration/lib/darwin/run.sh | 11 ++---- images/build-integration/lib/linux/run.sh | 12 ++---- images/build-integration/lib/windows/run.ps1 | 12 ++---- test/integration/testsuite_test.go | 39 +++++++++++--------- 5 files changed, 36 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index 8839c6191c..6d1b42bcfd 100644 --- a/Makefile +++ b/Makefile @@ -231,17 +231,17 @@ containerized_integration: clean .PHONY: integration ## Run integration tests in Ginkgo integration: ifndef GINKGO_OPTS -export GINKGO_OPTS = --ginkgo.label-filter="" +GINKGO_OPTS = --ginkgo.label-filter="" endif ifndef PULL_SECRET_PATH -export PULL_SECRET_PATH = $(HOME)/Downloads/crc-pull-secret +PULL_SECRET_PATH = --pull-secret-path=$(HOME)/Downloads/crc-pull-secret endif ifndef BUNDLE_PATH -export BUNDLE_PATH = $(HOME)/Downloads/crc_libvirt_$(OPENSHIFT_VERSION)_$(GOARCH).$(BUNDLE_EXTENSION) +BUNDLE_PATH = --bundle-path=$(HOME)/Downloads/crc_libvirt_$(OPENSHIFT_VERSION)_$(GOARCH).$(BUNDLE_EXTENSION) endif integration: - @go test -timeout=90m -tags "$(BUILDTAGS)" $(MODULEPATH)/test/integration -v $(GINKGO_OPTS) + @go test -timeout=90m -tags "$(BUILDTAGS)" $(MODULEPATH)/test/integration $(PULL_SECRET_PATH) $(BUNDLE_PATH) -v $(GINKGO_OPTS) .PHONY: e2e ## Run e2e tests e2e: diff --git a/images/build-integration/lib/darwin/run.sh b/images/build-integration/lib/darwin/run.sh index c60ffa12ce..7f7c2424a7 100755 --- a/images/build-integration/lib/darwin/run.sh +++ b/images/build-integration/lib/darwin/run.sh @@ -44,20 +44,15 @@ mkdir -p $targetFolder/results # Run tests export PATH="$PATH:${HOME}/$targetFolder/bin" -export PULL_SECRET_PATH="${HOME}/$targetFolder/pull-secret" -if [ ! -z "$bundleLocation" ] -then - export BUNDLE_PATH="$bundleLocation" -fi cd $targetFolder/bin if [ ! -z "$labelFilter" ] then - ./integration.test --ginkgo.timeout $suiteTimeout --ginkgo.label-filter $labelFilter > integration.results + ./integration.test --pull-secret-path="${HOME}/$targetFolder/pull-secret" --bundle-path=$bundleLocation --ginkgo.timeout $suiteTimeout --ginkgo.label-filter $labelFilter > integration.results else - ./integration.test --ginkgo.timeout $suiteTimeout > integration.results + ./integration.test --pull-secret-path="${HOME}/$targetFolder/pull-secret" --bundle-path=$bundleLocation --ginkgo.timeout $suiteTimeout > integration.results fi # Copy results cd .. cp bin/integration.results results/integration.results -cp bin/out/integration.xml results/$junitFilename \ No newline at end of file +cp bin/out/integration.xml results/$junitFilename diff --git a/images/build-integration/lib/linux/run.sh b/images/build-integration/lib/linux/run.sh index bb4f5c179f..f048ca28fd 100755 --- a/images/build-integration/lib/linux/run.sh +++ b/images/build-integration/lib/linux/run.sh @@ -45,20 +45,16 @@ mkdir -p $targetFolder/results # Run tests export PATH="$PATH:${HOME}/$targetFolder/bin" -export PULL_SECRET_PATH="${HOME}/$targetFolder/pull-secret" -if [ ! -z "$bundleLocation" ] -then - export BUNDLE_PATH="$bundleLocation" -fi + cd $targetFolder/bin if [ ! -z "$labelFilter" ] then - ./integration.test --ginkgo.timeout $suiteTimeout --ginkgo.label-filter $labelFilter > integration.results + ./integration.test --pull-secret-path="${HOME}/$targetFolder/pull-secret" --bundle-path=$bundleLocation --ginkgo.timeout $suiteTimeout --ginkgo.label-filter $labelFilter > integration.results else - ./integration.test --ginkgo.timeout $suiteTimeout > integration.results + ./integration.test --pull-secret-path="${HOME}/$targetFolder/pull-secret" --bundle-path=$bundleLocation --ginkgo.timeout $suiteTimeout > integration.results fi # Copy results cd .. cp bin/integration.results results/integration.results -cp bin/out/integration.xml results/$junitFilename \ No newline at end of file +cp bin/out/integration.xml results/$junitFilename diff --git a/images/build-integration/lib/windows/run.ps1 b/images/build-integration/lib/windows/run.ps1 index 2bdcd7a7ed..ddf4ceed10 100755 --- a/images/build-integration/lib/windows/run.ps1 +++ b/images/build-integration/lib/windows/run.ps1 @@ -21,19 +21,15 @@ New-Item -ItemType directory -Path "$env:HOME\$targetFolder\results" -Force # Run tests cd $targetFolder\bin -if ($bundleLocation) { - $env:BUNDLE_PATH="$bundleLocation" -} -# We need to copy the pull-secret to the target folder -$env:PULL_SECRET_PATH="$env:HOME\$targetFolder\pull-secret" + if ($labelFilter) { - integration.test.exe --ginkgo.timeout $suiteTimeout --ginkgo.label-filter $labelFilter > integration.results + integration.test.exe --pull-secret-path="$env:HOME\$targetFolder\pull-secret" --bundle-path=$bundleLocation --ginkgo.timeout $suiteTimeout --ginkgo.label-filter $labelFilter > integration.results } else { - integration.test.exe --ginkgo.timeout $suiteTimeout > integration.results + integration.test.exe --pull-secret-path="$env:HOME\$targetFolder\pull-secret" --bundle-path=$bundleLocation --ginkgo.timeout $suiteTimeout > integration.results } # Copy results cd .. cp bin\integration.results results\integration.results -cp bin\out\integration.xml results\$junitFilename \ No newline at end of file +cp bin\out\integration.xml results\$junitFilename diff --git a/test/integration/testsuite_test.go b/test/integration/testsuite_test.go index 0e9ecdba1b..84f453c4b8 100644 --- a/test/integration/testsuite_test.go +++ b/test/integration/testsuite_test.go @@ -12,6 +12,9 @@ import ( . "github.com/onsi/gomega" gomegaformat "github.com/onsi/gomega/format" "github.com/sirupsen/logrus" + + "flag" + "github.com/spf13/pflag" ) type VersionAnswer struct { @@ -25,9 +28,22 @@ var userHome string var versionInfo VersionAnswer var bundlePath string -var ginkgoOpts string var pullSecretPath string + +func TestMain(m *testing.M) { + RegisterFlags(flag.CommandLine) + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + os.Exit(m.Run()) +} + +func RegisterFlags(flags *flag.FlagSet) { + flags.StringVar(&bundlePath, "bundle-path", "", "Path to the bundle to be used in tests.") + flags.StringVar(&pullSecretPath, "pull-secret-path", "", "Path to the file containing pull secret.") +} + func TestTest(t *testing.T) { RegisterFailHandler(Fail) @@ -76,25 +92,12 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) - bundlePath = os.Getenv("BUNDLE_PATH") // this env var should contain location of bundle - if bundlePath != "" { + if len(bundlePath) != 0 { Expect(bundlePath).To(BeAnExistingFile()) } - ginkgoOpts = os.Getenv("GINKGO_OPTS") - if err != nil { - - logrus.Infof("Error: Could not read GINKGO_OPTS.") - logrus.Infof("%v", err) - } - Expect(err).NotTo(HaveOccurred()) - - pullSecretPath = os.Getenv("PULL_SECRET_PATH") // this env var should contain location of pull-secret file - if err != nil { - - logrus.Infof("Error: You need to set PULL_SECRET_PATH to find CRC useful.") - logrus.Infof("%v", err) + if len(pullSecretPath) == 0 { + logrus.Infof("Error: You need to set PULL_SECRET_PATH for CRC to function properly.") } - Expect(err).NotTo(HaveOccurred()) - + Expect(pullSecretPath).NotTo(BeEmpty()) })