diff options
| -rw-r--r-- | tests/e2e/deployment/e2e_test.go (renamed from tests/e2e/deployment/deployment_suite_test.go) | 18 | ||||
| -rw-r--r-- | tests/e2e/keadm/keadm_suite_test.go | 13 | ||||
| -rwxr-xr-x | tests/e2e/scripts/fast_test.sh | 30 | ||||
| -rwxr-xr-x | tests/e2e/scripts/keadm_deprecated_e2e.sh | 22 | ||||
| -rwxr-xr-x | tests/e2e/scripts/keadm_e2e.sh | 23 | ||||
| -rw-r--r-- | tests/e2e/utils/config.go | 57 |
6 files changed, 80 insertions, 83 deletions
diff --git a/tests/e2e/deployment/deployment_suite_test.go b/tests/e2e/deployment/e2e_test.go index 07392b511..fabd44276 100644 --- a/tests/e2e/deployment/deployment_suite_test.go +++ b/tests/e2e/deployment/e2e_test.go @@ -17,10 +17,13 @@ limitations under the License. package deployment import ( + "flag" + "os" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/spf13/pflag" "github.com/kubeedge/kubeedge/tests/e2e/utils" ) @@ -28,16 +31,23 @@ import ( var ( nodeName string nodeSelector string - //context to load config and access across the package + // context to load config and access across the package ctx *utils.TestContext ) -//Function to run the Ginkgo Test -func TestEdgecoreAppDeployment(t *testing.T) { +func TestMain(m *testing.M) { + utils.CopyFlags(utils.Flags, flag.CommandLine) + utils.RegisterFlags(flag.CommandLine) + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + os.Exit(m.Run()) +} + +// Function to run the Ginkgo Test +func TestE2E(t *testing.T) { RegisterFailHandler(Fail) var _ = BeforeSuite(func() { utils.Infof("Before Suite Execution") - //cfg = utils.LoadConfig() ctx = utils.NewTestContext(utils.LoadConfig()) nodeName = "edge-node" nodeSelector = "test" diff --git a/tests/e2e/keadm/keadm_suite_test.go b/tests/e2e/keadm/keadm_suite_test.go index 953f7e090..e692e436b 100644 --- a/tests/e2e/keadm/keadm_suite_test.go +++ b/tests/e2e/keadm/keadm_suite_test.go @@ -17,10 +17,13 @@ limitations under the License. package keadm import ( + "flag" + "os" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/spf13/pflag" "github.com/kubeedge/kubeedge/tests/e2e/utils" ) @@ -32,7 +35,15 @@ var ( ctx *utils.TestContext ) -//Function to run the Ginkgo Test +func TestMain(m *testing.M) { + utils.CopyFlags(utils.Flags, flag.CommandLine) + utils.RegisterFlags(flag.CommandLine) + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + os.Exit(m.Run()) +} + +// Function to run the Ginkgo Test func TestKeadmAppDeployment(t *testing.T) { RegisterFailHandler(Fail) var _ = BeforeSuite(func() { diff --git a/tests/e2e/scripts/fast_test.sh b/tests/e2e/scripts/fast_test.sh index f0655bfca..47014e614 100755 --- a/tests/e2e/scripts/fast_test.sh +++ b/tests/e2e/scripts/fast_test.sh @@ -19,31 +19,31 @@ workdir=`pwd` cd $workdir compilemodule=$1 -runtest=$2 -debugflag="-test.v -ginkgo.v" #setup env cd ../ export MASTER_IP=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test-control-plane` export KUBECONFIG=$HOME/.kube/config - export CHECK_EDGECORE_ENVIRONMENT="false" - -#Pre-configurations required for running the suite. -#Any new config addition required corresponding code changes. -cat >config.json<<END -{ - "image_url": ["nginx", "nginx"], - "k8smasterforkubeedge":"https://$MASTER_IP:6443", - "kubeconfigpath":"$KUBECONFIG" -} -END +export ACK_GINKGO_RC=true if [ $# -eq 0 ] then #run testcase - ./deployment/deployment.test $debugflag 2>&1 | tee -a /tmp/testcase.log + ginkgo -v ./deployment/deployment.test -- \ + --image-url=nginx \ + --image-url=nginx \ + --kube-master="https://$MASTER_IP:6443" \ + --kubeconfig=$KUBECONFIG \ + --test.v \ + 2>&1 | tee -a /tmp/testcase.log else - ./$compilemodule/$compilemodule.test $debugflag $runtest 2>&1 | tee -a /tmp/testcase.log + ginkgo -v ./$compilemodule/$compilemodule.test -- \ + --image-url=nginx \ + --image-url=nginx \ + --kube-master="https://$MASTER_IP:6443" \ + --kubeconfig=$KUBECONFIG \ + --test.v \ + 2>&1 | tee -a /tmp/testcase.log fi diff --git a/tests/e2e/scripts/keadm_deprecated_e2e.sh b/tests/e2e/scripts/keadm_deprecated_e2e.sh index 068c49795..087fe323a 100755 --- a/tests/e2e/scripts/keadm_deprecated_e2e.sh +++ b/tests/e2e/scripts/keadm_deprecated_e2e.sh @@ -18,7 +18,6 @@ KUBEEDGE_ROOT=$PWD WORKDIR=$(dirname $0) E2E_DIR=$(realpath $(dirname $0)/..) -debugflag="-test.v -ginkgo.v" source "${KUBEEDGE_ROOT}/hack/lib/golang.sh" kubeedge::version::get_version_info VERSION=${GIT_VERSION} @@ -70,16 +69,6 @@ function start_kubeedge() { sudo systemctl set-environment CHECK_EDGECORE_ENVIRONMENT="false" sudo -E CHECK_EDGECORE_ENVIRONMENT="false" _output/local/bin/keadm deprecated join --token=$TOKEN --cloudcore-ipport=127.0.0.1:10000 --edgenode-name=edge-node --kubeedge-version=${KUBEEDGE_VERSION} - #Pre-configurations required for running the suite. - #Any new config addition required corresponding code changes. - cat > $E2E_DIR/config.json <<END -{ - "image_url": ["nginx", "nginx"], - "k8smasterforkubeedge":"https://$MASTER_IP:6443", - "kubeconfigpath":"$KUBECONFIG" -} -END - # ensure edgenode is ready while true; do sleep 3 @@ -90,7 +79,16 @@ END function run_test() { :> /tmp/testcase.log cd $E2E_DIR - ./keadm/keadm.test $debugflag 2>&1 | tee -a /tmp/testcase.log + + export ACK_GINKGO_RC=true + + ginkgo -v ./keadm/keadm.test -- \ + --image-url=nginx \ + --image-url=nginx \ + --kube-master="https://$MASTER_IP:6443" \ + --kubeconfig=$KUBECONFIG \ + --test.v \ + 2>&1 | tee -a /tmp/testcase.log #stop the edgecore after the test completion grep -e "Running Suite" -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | sed -r 's/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' diff --git a/tests/e2e/scripts/keadm_e2e.sh b/tests/e2e/scripts/keadm_e2e.sh index 5a608ce09..df462375a 100755 --- a/tests/e2e/scripts/keadm_e2e.sh +++ b/tests/e2e/scripts/keadm_e2e.sh @@ -20,8 +20,6 @@ E2E_DIR=$(realpath $(dirname $0)/..) IMAGE_TAG=$(git describe --tags) KUBEEDGE_VERSION=$IMAGE_TAG -debugflag="-test.v -ginkgo.v" - function cleanup() { sudo pkill edgecore || true helm uninstall cloudcore -n kubeedge && kubectl delete ns kubeedge || true @@ -74,16 +72,6 @@ function start_kubeedge() { sudo systemctl set-environment CHECK_EDGECORE_ENVIRONMENT="false" sudo -E CHECK_EDGECORE_ENVIRONMENT="false" /usr/local/bin/keadm join --token=$TOKEN --cloudcore-ipport=$MASTER_IP:10000 --edgenode-name=edge-node --kubeedge-version=$KUBEEDGE_VERSION - #Pre-configurations required for running the suite. - #Any new config addition required corresponding code changes. - cat > $E2E_DIR/config.json <<END -{ - "image_url": ["nginx", "nginx"], - "k8smasterforkubeedge":"https://$MASTER_IP:6443", - "kubeconfigpath":"$KUBECONFIG" -} -END - # ensure edgenode is ready while true; do sleep 3 @@ -94,7 +82,16 @@ END function run_test() { :> /tmp/testcase.log cd $E2E_DIR - ./keadm/keadm.test $debugflag 2>&1 | tee -a /tmp/testcase.log + + export ACK_GINKGO_RC=true + + ginkgo -v ./keadm/keadm.test -- \ + --image-url=nginx \ + --image-url=nginx \ + --kube-master="https://$MASTER_IP:6443" \ + --kubeconfig=$KUBECONFIG \ + --test.v \ + 2>&1 | tee -a /tmp/testcase.log #stop the edgecore after the test completion grep -e "Running Suite" -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | sed -r 's/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' diff --git a/tests/e2e/utils/config.go b/tests/e2e/utils/config.go index b086cacda..286708706 100644 --- a/tests/e2e/utils/config.go +++ b/tests/e2e/utils/config.go @@ -16,11 +16,13 @@ limitations under the License. package utils import ( - "encoding/json" + "flag" "math/rand" "os" - "path/filepath" "time" + + "k8s.io/client-go/tools/clientcmd" + cliflag "k8s.io/component-base/cli/flag" ) //config.json decode struct @@ -36,49 +38,28 @@ type Config struct { KubeConfigPath string `json:"kubeconfigpath"` } -//config struct -var config *Config +// config struct +var config Config +var Flags = flag.NewFlagSet("", flag.ContinueOnError) -//get config.json path -func LoadConfig() Config { - if config == nil { - config = loadConfigJSOMFromPath() - } - return *config +func RegisterFlags(flags *flag.FlagSet) { + flags.StringVar(&config.KubeConfigPath, "kubeconfig", os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to kubeconfig containing embedded authinfo.") + flags.Var(cliflag.NewStringSlice(&config.AppImageURL), "image-url", "image url list for e2e") + flags.StringVar(&config.K8SMasterForKubeEdge, "kube-master", "", "the kubernetes master address") } -//loadConfigJSOMFromPath reads the test configuration and builds a Config object. -func loadConfigJSOMFromPath() *Config { - path := getConfigPath() - _, err := filepath.Abs(filepath.Dir(path)) - if err != nil { - Infof("Failed to get Abs path: %v", err) - panic(err) - } - var config = &Config{} - configFile, err := os.Open(path) - if err != nil { - panic(err) - } - decoder := json.NewDecoder(configFile) - err = decoder.Decode(config) - if err != nil { - panic(err) - } - return config +func CopyFlags(source *flag.FlagSet, target *flag.FlagSet) { + source.VisitAll(func(flag *flag.Flag) { + target.Var(flag.Value, flag.Name, flag.Usage) + }) } -//getConfigPath returns the configuration path provided in the env var name. In case the env var is not -//set, the default configuration path is returned -func getConfigPath() string { - path := os.Getenv("TESTCONFIG") - if path == "" { - path = "config.json" - } - return path +// get config.json path +func LoadConfig() Config { + return config } -//function to Generate Random string +// function to Generate Random string func GetRandomString(length int) string { str := "0123456789abcdefghijklmnopqrstuvwxyz" bytes := []byte(str) |
