From d32b9b0ae8e19c3ca24bec2b98010bde9efdcc76 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Mon, 27 Jun 2022 17:23:26 +0200 Subject: [PATCH] rename assets folder Signed-off-by: Jorge Turrado --- tests/README.md | 10 +-- tests/assets/cleanup_test.go | 34 --------- tests/assets/setup_test.go | 132 ----------------------------------- tests/run-all.sh | 6 +- tests/run-arm-smoke-tests.sh | 4 +- 5 files changed, 10 insertions(+), 176 deletions(-) delete mode 100644 tests/assets/cleanup_test.go delete mode 100644 tests/assets/setup_test.go diff --git a/tests/README.md b/tests/README.md index 5c73c2bac95..4ba76010292 100644 --- a/tests/README.md +++ b/tests/README.md @@ -9,9 +9,9 @@ ### All tests ```bash -go test -v assets/setup_test.go # Only needs to be run once. +go test -v utils/setup_test.go # Only needs to be run once. go test -v ./scalers_go/... -go test -v assets/cleanup_test.go # Skip if you want to keep testing. +go test -v utils/cleanup_test.go # Skip if you want to keep testing. ``` ### Specific test @@ -26,15 +26,15 @@ Refer to [this](https://pkg.go.dev/testing) for more information about testing i The test script will run in 3 phases: -- **Setup:** This is done in [`assets/setup_test.go`](assets/setup_test.go). If you're adding any tests to the KEDA install / setup process, you need to add it to this file. `assets/setup_test.go` deploys KEDA to the `keda` namespace, updates the image to +- **Setup:** This is done in [`utils/setup_test.go`](utils/setup_test.go). If you're adding any tests to the KEDA install / setup process, you need to add it to this file. `utils/setup_test.go` deploys KEDA to the `keda` namespace, updates the image to `kedacore/keda:main`. - After `assets/setup_test.go` is done, we expect to have KEDA setup in the `keda` namespace. + After `utils/setup_test.go` is done, we expect to have KEDA setup in the `keda` namespace. - **Tests:** Currently there are only scaler tests in `tests/scalers_go/`. Each test is kept in its own package. This is to prevent conflicting variable declarations for commoly used variables (**ex -** `testNamespace`). Individual scaler tests are run in parallel, but tests within a file can be run in parallel or in series. More about tests below. -- **Global cleanup:** This is done in [`assets/cleanup_test.go`](assets/cleanup_test.go). It cleans up all the resources created in `assets/setup_test.go`. +- **Global cleanup:** This is done in [`utils/cleanup_test.go`](utils/cleanup_test.go). It cleans up all the resources created in `utils/setup_test.go`. ## Adding tests diff --git a/tests/assets/cleanup_test.go b/tests/assets/cleanup_test.go deleted file mode 100644 index 48487d0eaf0..00000000000 --- a/tests/assets/cleanup_test.go +++ /dev/null @@ -1,34 +0,0 @@ -//go:build e2e -// +build e2e - -package assets - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/require" - - . "github.com/kedacore/keda/v2/tests/helper" -) - -func TestRemoveKEDA(t *testing.T) { - out, err := ExecuteCommandWithDir("make undeploy", "..") - require.NoErrorf(t, err, "error removing KEDA - %s", err) - - t.Log(string(out)) - t.Log("KEDA removed successfully using 'make undeploy' command") -} - -func TestRemoveWorkloadIdentityComponents(t *testing.T) { - if AzureRunWorkloadIdentityTests == "" || AzureRunWorkloadIdentityTests == "false" { - t.Skip("skipping as workload identity tests are disabled") - } - - _, err := ExecuteCommand(fmt.Sprintf("helm uninstall workload-identity-webhook --namespace %s", AzureWorkloadIdentityNamespace)) - require.NoErrorf(t, err, "cannot uninstall workload identity webhook - %s", err) - - Kc = GetKubernetesClient(t) - - DeleteNamespace(t, Kc, AzureWorkloadIdentityNamespace) -} diff --git a/tests/assets/setup_test.go b/tests/assets/setup_test.go deleted file mode 100644 index d8e4e562764..00000000000 --- a/tests/assets/setup_test.go +++ /dev/null @@ -1,132 +0,0 @@ -//go:build e2e -// +build e2e - -package assets - -import ( - "context" - "fmt" - "os/exec" - "testing" - "time" - - "github.com/stretchr/testify/require" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - . "github.com/kedacore/keda/v2/tests/helper" -) - -func TestVerifyCommands(t *testing.T) { - commands := []string{"kubectl"} - for _, cmd := range commands { - _, err := exec.LookPath(cmd) - require.NoErrorf(t, err, "%s is required for setup - %s", cmd, err) - } -} - -func TestKubernetesConnection(t *testing.T) { - Kc = GetKubernetesClient(t) -} - -func TestKubernetesVersion(t *testing.T) { - out, err := ExecuteCommand("kubectl version") - require.NoErrorf(t, err, "error getting kubernetes version - %s", err) - - t.Logf("kubernetes version: %s", string(out)) -} - -func TestSetupHelm(t *testing.T) { - _, err := exec.LookPath("helm") - if err == nil { - t.Skip("helm is already installed. skipping setup.") - } - - _, err = ExecuteCommand("curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3") - require.NoErrorf(t, err, "cannot download helm installation shell script - %s", err) - - _, err = ExecuteCommand("chmod 700 get_helm.sh") - require.NoErrorf(t, err, "cannot change permissions for helm installation script - %s", err) - - _, err = ExecuteCommand("./get_helm.sh") - require.NoErrorf(t, err, "cannot download helm - %s", err) - - _, err = ExecuteCommand("helm version") - require.NoErrorf(t, err, "cannot get helm version - %s", err) -} - -func TestSetupWorkloadIdentityComponents(t *testing.T) { - if AzureRunWorkloadIdentityTests == "" || AzureRunWorkloadIdentityTests == "false" { - t.Skip("skipping as workload identity tests are disabled") - } - - _, err := ExecuteCommand("helm version") - require.NoErrorf(t, err, "helm is not installed - %s", err) - - _, err = ExecuteCommand("helm repo add azure-workload-identity https://azure.github.io/azure-workload-identity/charts") - require.NoErrorf(t, err, "cannot add workload identity helm repo - %s", err) - - _, err = ExecuteCommand("helm repo update azure-workload-identity") - require.NoErrorf(t, err, "cannot update workload identity helm repo - %s", err) - - Kc = GetKubernetesClient(t) - CreateNamespace(t, Kc, AzureWorkloadIdentityNamespace) - - _, err = ExecuteCommand(fmt.Sprintf("helm upgrade --install workload-identity-webhook azure-workload-identity/workload-identity-webhook --namespace %s --set azureTenantID=%s", - AzureWorkloadIdentityNamespace, AzureADTenantID)) - require.NoErrorf(t, err, "cannot install workload identity webhook - %s", err) - - workloadIdentityDeploymentName := "azure-wi-webhook-controller-manager" - success := false - for i := 0; i < 20; i++ { - deployment, err := Kc.AppsV1().Deployments(AzureWorkloadIdentityNamespace).Get(context.Background(), workloadIdentityDeploymentName, v1.GetOptions{}) - require.NoErrorf(t, err, "unable to get workload identity webhook deployment - %s", err) - - readyReplicas := deployment.Status.ReadyReplicas - if readyReplicas != 2 { - t.Log("workload identity webhook is not ready. sleeping") - time.Sleep(5 * time.Second) - } else { - t.Log("workload identity webhook is ready") - success = true - - time.Sleep(2 * time.Minute) // sleep for some time for webhook to setup properly - break - } - } - - require.True(t, success, "expected workload identity webhook deployment to start 2 pods successfully") -} - -func TestDeployKEDA(t *testing.T) { - out, err := ExecuteCommandWithDir("make deploy", "..") - require.NoErrorf(t, err, "error deploying KEDA - %s", err) - - t.Log(string(out)) - t.Log("KEDA deployed successfully using 'make deploy' command") -} - -func TestVerifyKEDA(t *testing.T) { - success := false - for i := 0; i < 20; i++ { - operatorDeployment, err := Kc.AppsV1().Deployments(KEDANamespace).Get(context.Background(), KEDAOperator, v1.GetOptions{}) - require.NoErrorf(t, err, "unable to get %s deployment - %s", KEDAOperator, err) - - metricsServerDeployment, err := Kc.AppsV1().Deployments(KEDANamespace).Get(context.Background(), KEDAMetricsAPIServer, v1.GetOptions{}) - require.NoErrorf(t, err, "unable to get %s deployment - %s", KEDAMetricsAPIServer, err) - - operatorReadyReplicas := operatorDeployment.Status.ReadyReplicas - metricsServerReadyReplicas := metricsServerDeployment.Status.ReadyReplicas - - if operatorReadyReplicas != 1 || metricsServerReadyReplicas != 1 { - t.Log("KEDA is not ready. sleeping") - time.Sleep(5 * time.Second) - } else { - t.Logf("KEDA is running 1 pod for %s and 1 pod for %s", KEDAOperator, KEDAMetricsAPIServer) - success = true - - break - } - } - - require.True(t, success, "expected KEDA deployments to start 2 pods successfully") -} diff --git a/tests/run-all.sh b/tests/run-all.sh index 78cffb6980d..42cfb965201 100755 --- a/tests/run-all.sh +++ b/tests/run-all.sh @@ -17,14 +17,14 @@ counter=0 executed_count=0 function run_setup { - go test -v -tags e2e assets/setup_test.go + go test -v -tags e2e utils/setup_test.go } function run_tests { counter=0 # randomize tests order using shuf # TODO - Remove TypeScript regex after all tests have been migrated to Go. - for test_case in $(find . -not -path '*/assets/*' -wholename "$E2E_REGEX_GO" -o -wholename "$E2E_REGEX_TS" | shuf) + for test_case in $(find . -not -path '*/utils/*' -wholename "$E2E_REGEX_GO" -o -wholename "$E2E_REGEX_TS" | shuf) do if [[ $test_case != *_test.go && $test_case != *.test.ts ]] # Skip helper files then @@ -131,7 +131,7 @@ function print_logs { } function run_cleanup { - go test -v -tags e2e assets/cleanup_test.go + go test -v -tags e2e utils/cleanup_test.go } function print_failed { diff --git a/tests/run-arm-smoke-tests.sh b/tests/run-arm-smoke-tests.sh index dd575ab41fd..2ea9fc151b4 100755 --- a/tests/run-arm-smoke-tests.sh +++ b/tests/run-arm-smoke-tests.sh @@ -19,7 +19,7 @@ failed_lookup=() counter=0 function run_setup { - go test -v -tags e2e assets/setup_test.go + go test -v -tags e2e utils/setup_test.go } function run_tests { @@ -127,7 +127,7 @@ function print_logs { } function run_cleanup { - go test -v -tags e2e assets/cleanup_test.go + go test -v -tags e2e utils/cleanup_test.go } function print_failed {