Skip to content

Commit

Permalink
feat: egress e2e test
Browse files Browse the repository at this point in the history
* add simple e2e test for egress TLS gateway

This tests implements the official Istio egress tutorial with TLS passthrough.

Note that this test will work only on a cluster that supports NetworkPolicy. For local cluster only kind supports NetworkPolicies.
  • Loading branch information
Ressetkk committed Feb 9, 2025
1 parent 5c40257 commit 9e1a147
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/call-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test_make_target: [ "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
test_make_target: [ "test-e2e", "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test_make_target: [ "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
test_make_target: [ "test-e2e", "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
steps:
- uses: actions/checkout@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/post-main-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test_make_target: [ "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
test_make_target: [ "test-e2e", "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test_make_target: [ "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
test_make_target: [ "test-e2e", "configuration-integration-test", "mesh-communication-integration-test", "installation-integration-test", "observability-integration-test" ]
steps:
- uses: actions/checkout@v4
with:
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: gotestsum
gotestsum:
test -s $(LOCALBIN)/gotestsum || GOBIN=$(LOCALBIN) go install gotest.tools/gotestsum@latest

.PHONY: yq
yq: $(YQUERY) ## Download yq locally if necessary.
$(YQUERY): $(LOCALBIN)
Expand All @@ -192,6 +196,9 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: test-e2e
test-e2e: gotestsum
$(LOCALBIN)/gotestsum --format "testname" -- -run '^TestE2E.*' ./tests/e2e/...
##@ Module

.PHONY: module-image
Expand Down
56 changes: 56 additions & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# End-to-end tests

This directory contains definitions and implementations of end-to-end tests for istio operator.
These tests are for testing the connectivity of istio components to external services, implementing user scenarios.

## Running end-to-end tests

E2E tests run against cluster that is set up as active in your `KUBECONFIG` file. If you want to change the target,
export an environment vairable `KUBECONFIG` to specific kubeconfig file. Make sure you have admin permission on a
cluster.

To run the E2E tests, use `make test-e2e` command in project root directory.
You can also use `go test -run '^TestE2E.*' ./tests/e2e/...`directly, if you don't want to use make.

## Writing end-to-end tests

If you want to add another E2E test, there are several topics to follow.

Tests use lightweight testing framework included in the Go language.
For more information and reference, read the official Testing package documentation: https://pkg.go.dev/testing.

The tests are separate functions that expect that test cluster is configured with Istio manager installed without Istio CR applied.
Each function has to configure the cluster in runtime and then clean up the cluster back to initial state, removing all resources that were created.

For cleanup tasks, use default `t.Cleanup()` function from Testing package.

For helper functions use `t.Helper()` call. Each helper function should accept `t *testing.T` as argument.
Returning errors in this case is not really necessary. Just use `t.Error()` or `t.Fatal()` like with usual tests.

Avoid using global variables unless necessary. Do not import variables from other test packages, unless the external
package is a library.

For logging additional information, use default `t.Log()` and `t.Logf()` functions from Testing package.

Each of the test should be put in its own package. Keep the fixtures under `testdata` directory in the same package.

Put libraries used in tests under `pkg` directory, just as in standard Go project scheme.

Function body does not follow a strict methodology. Just keep it simple. Usually they are written as procedural functions.
If you need to implement more advanced logic, remember to not leak the implementation outside the package/function.

Start name of each function with prefix `TestE2E`.
When running `go test`, we set up pattern for running tests that only start with this prefix.

When you want to conditionally run specific test, use environment variables.
Those environment variables must be set in the environment before running `go test`. Do not set the variable in the test file.
For example, when the test should run only on gardener, add the simple if statement at the beginning of your test function:
```go
if os.Getenv("VARIABLE") == "true" {
// for better visibility, add message in the function call
t.Skip()
}
```

When you need to test multiple options in single configuration of a cluster, consider using table-driven tests.
For more information, follow official Go documentation: https://go.dev/wiki/TableDrivenTests.
Loading

0 comments on commit 9e1a147

Please sign in to comment.