Skip to content

Commit

Permalink
chore: Split e2e by type (#3283)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Turrado Ferrero authored Jul 5, 2022
1 parent 667d716 commit c0934de
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ To learn more about our roadmap, we recommend reading [this document](ROADMAP.md
- **General:** Improve error message in resolving ServiceAccount for AWS EKS PodIdentity ([3142](https://github.com/kedacore/keda/issues/3142))
- **General:** Improve e2e on PR process. ([3004](https://github.com/kedacore/keda/issues/3004))
- **General:** Migrate e2e test to Go. ([2737](https://github.com/kedacore/keda/issues/2737))
- **General:** Split e2e test by functionality. ([#3270](https://github.com/kedacore/keda/issues/3270))
- **General:** Unify the used tooling on different workflows and arch. ([3092](https://github.com/kedacore/keda/issues/3092))
- **General:** Use Github's Checks API for e2e tests on PR. ([2567](https://github.com/kedacore/keda/issues/2567))

Expand Down
17 changes: 11 additions & 6 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
### All tests

```bash
go test -v 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 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
Expand All @@ -26,22 +26,27 @@ 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 [`setup_test.go`](setup_test.go). If you're adding any tests to the KEDA install / setup process, you need to add it to this file. `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 `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 [`cleanup_test.go`](cleanup_test.go). It cleans up all the resources created in `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

- Tests are written using `Go`'s default [`testing`](https://pkg.go.dev/testing) framework, and [`testify`](https://pkg.go.dev/github.com/stretchr/testify).
- Each scaler should be in its own package, **ex -** `scalers_go/azure_queue/azure_queue_test.go`, or `scalers_go/kafka/kafka_test.go`, etc
- Each e2e test should be in its own package, **ex -** `scalers_go/azure_queue/azure_queue_test.go`, or `scalers_go/kafka/kafka_test.go`, etc
- Each test file is expected to do its own setup and clean for resources.

Test are split in different folders based on what it's testing:
- `internals`: KEDA internals (ie: HPA related stuff).
- `scalers_go`: Anything related with scalers.
- `secret-providers`: Anything related with how KEDA gets the secrets for working (ie: pod-identity, vault, etc).

#### ⚠⚠ Important: ⚠⚠
>
> - Even though the cleaning of resources is expected inside each e2e test file, all test namespaces
Expand Down
10 changes: 5 additions & 5 deletions tests/run-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -u

# TODO - Remove TypeScript regex after all tests have been migrated to Go.
E2E_REGEX_GO="./scalers*${E2E_TEST_REGEX:-*_test.go}"
E2E_REGEX_TS="./scalers*${E2E_TEST_REGEX:-*.test.ts}"
E2E_REGEX_GO="./${E2E_TEST_REGEX:-*_test.go}"
E2E_REGEX_TS="./${E2E_TEST_REGEX:-*.test.ts}"

DIR=$(dirname "$0")
cd $DIR
Expand All @@ -17,14 +17,14 @@ counter=0
executed_count=0

function run_setup {
go test -v -tags e2e 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 . -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
Expand Down Expand Up @@ -131,7 +131,7 @@ function print_logs {
}

function run_cleanup {
go test -v -tags e2e cleanup_test.go
go test -v -tags e2e utils/cleanup_test.go
}

function print_failed {
Expand Down
4 changes: 2 additions & 2 deletions tests/run-arm-smoke-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ failed_lookup=()
counter=0

function run_setup {
go test -v -tags e2e setup_test.go
go test -v -tags e2e utils/setup_test.go
}

function run_tests {
Expand Down Expand Up @@ -126,7 +126,7 @@ function print_logs {
}

function run_cleanup {
go test -v -tags e2e cleanup_test.go
go test -v -tags e2e utils/cleanup_test.go
}

function print_failed {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build e2e
// +build e2e

package azure_keyvault_queue_test
package azure_keyvault_test

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions tests/cleanup_test.go → tests/utils/cleanup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build e2e
// +build e2e

package tests
package utils

import (
"fmt"
Expand All @@ -13,7 +13,7 @@ import (
)

func TestRemoveKEDA(t *testing.T) {
out, err := ExecuteCommandWithDir("make undeploy", "..")
out, err := ExecuteCommandWithDir("make undeploy", "../..")
require.NoErrorf(t, err, "error removing KEDA - %s", err)

t.Log(string(out))
Expand All @@ -28,7 +28,7 @@ func TestRemoveWorkloadIdentityComponents(t *testing.T) {
_, err := ExecuteCommand(fmt.Sprintf("helm uninstall workload-identity-webhook --namespace %s", AzureWorkloadIdentityNamespace))
require.NoErrorf(t, err, "cannot uninstall workload identity webhook - %s", err)

KubeClient := GetKubernetesClient(t)
KubeClient = GetKubernetesClient(t)

DeleteNamespace(t, KubeClient, AzureWorkloadIdentityNamespace)
}
8 changes: 4 additions & 4 deletions tests/setup_test.go → tests/utils/setup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build e2e
// +build e2e

package tests
package utils

import (
"context"
Expand All @@ -25,7 +25,7 @@ func TestVerifyCommands(t *testing.T) {
}

func TestKubernetesConnection(t *testing.T) {
_ = GetKubernetesClient(t)
KubeClient = GetKubernetesClient(t)
}

func TestKubernetesVersion(t *testing.T) {
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestSetupWorkloadIdentityComponents(t *testing.T) {
_, err = ExecuteCommand("helm repo update azure-workload-identity")
require.NoErrorf(t, err, "cannot update workload identity helm repo - %s", err)

KubeClient := GetKubernetesClient(t)
KubeClient = GetKubernetesClient(t)
CreateNamespace(t, KubeClient, AzureWorkloadIdentityNamespace)

_, err = ExecuteCommand(fmt.Sprintf("helm upgrade --install workload-identity-webhook azure-workload-identity/workload-identity-webhook --namespace %s --set azureTenantID=%s",
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestSetupWorkloadIdentityComponents(t *testing.T) {
}

func TestDeployKEDA(t *testing.T) {
out, err := ExecuteCommandWithDir("make deploy", "..")
out, err := ExecuteCommandWithDir("make deploy", "../..")
require.NoErrorf(t, err, "error deploying KEDA - %s", err)

t.Log(string(out))
Expand Down

0 comments on commit c0934de

Please sign in to comment.