-
Notifications
You must be signed in to change notification settings - Fork 93
Integration tests #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+4,949
−15
Merged
Integration tests #929
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6797267
Add test harness
tomleb 617cd24
Add sorting tests
tomleb 9355576
Add filtering tests
tomleb 143aca3
Add columns tests
tomleb f0cf824
Update README
tomleb 6cc1993
Add GHA action for integration tests
tomleb acbd1b4
Check HTTP response code for sorting tests
tomleb bcafbf9
Check HTTP response code for columns tests
tomleb 771a0a1
Remove unnecessary comment
tomleb 58ee69a
Move integration tests to tests/integration
tomleb b4472cb
Fix waitForSchema for group-less resources
tomleb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Integration tests | ||
|
|
||
| on: | ||
| pull_request: {} | ||
| push: | ||
| branches: | ||
| - master | ||
| - release/* | ||
|
|
||
| jobs: | ||
| ci: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name : Checkout repository | ||
| # https://github.com/actions/checkout/releases/tag/v4.1.1 | ||
| uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 | ||
|
|
||
| - name: Install Go | ||
| # https://github.com/actions/setup-go/releases/tag/v5.0.0 | ||
| uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 | ||
| with: | ||
| go-version-file: 'go.mod' | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Install k3d | ||
| run: | | ||
| curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG=v5.8.3 bash | ||
|
|
||
| - name: Download dependencies | ||
| run: go mod download | ||
|
|
||
| - name: Run integration tests | ||
| run: make integration-tests | ||
| env: | ||
| INTEGRATION_TEST_ARGS: "-v -count=1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/bin/sh | ||
|
|
||
| CLUSTER_NAME=steve-integration-test | ||
|
|
||
| if [ -z "$KUBECONFIG" ] || [ -z "$(kubectl config get-contexts --no-headers)" ]; then | ||
| if ! docker version >/dev/null 2>&1; then | ||
| echo "docker not running" | ||
| exit 1 | ||
| fi | ||
|
|
||
| KUBECONFIG=$(mktemp) | ||
| export KUBECONFIG | ||
| if ! k3d kubeconfig get "$CLUSTER_NAME" > "$KUBECONFIG"; then | ||
| k3d cluster create "$CLUSTER_NAME" | ||
| fi | ||
| fi | ||
|
|
||
| set -x | ||
| RUN_INTEGRATION_TESTS=true go test $TEST_ARGS ./tests/... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Integration Tests | ||
|
|
||
| This document outlines how to run, debug and add new integration tests for steve. | ||
|
|
||
| ## Dependencies | ||
|
|
||
| To run the integration tests, you will need a running Kubernetes cluster. The tests will automatically target the cluster configured in your `KUBECONFIG` environment variable. | ||
|
|
||
| If you do not have a cluster configured, the tests will attempt to create a local one for you using [k3d](https://k3d.io/v5.6.0/#installation). This requires the following tools to be installed: | ||
|
|
||
| - [docker](https://docs.docker.com/get-docker/) | ||
| - [k3d](https://k3d.io/v5.6.0/#installation) | ||
|
|
||
| You will also need [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) to be installed and available in your `PATH`. | ||
|
|
||
| ## Running the tests | ||
|
|
||
| The integration tests can be run by executing the following command: | ||
|
|
||
| ```sh | ||
| make integration-tests | ||
| ``` | ||
|
|
||
| This will: | ||
| 1. Connect to the Kubernetes cluster defined by your `KUBECONFIG` environment variable. If no cluster is configured, it will try to create a `k3d` cluster named `steve-integration-test`. | ||
| 2. Run the Go tests located in the `tests/` directory. | ||
|
|
||
| ## Debugging | ||
|
|
||
| It is possible to pause the execution of a test to manually inspect the state of the cluster, the steve API and the SQLite database. This can be achieved by setting `INTEGRATION_TEST_DEBUG=true`: | ||
|
|
||
| ```sh | ||
| INTEGRATION_TEST_DEBUG=true make integration-tests | ||
| ``` | ||
|
|
||
| When a test is finished, it will print the following information and block until the test is cancelled (e.g. with `Ctrl+C`): | ||
|
|
||
| ``` | ||
| ########################### | ||
| # | ||
| # Integration tests stopped as requested | ||
| # | ||
| # You can now access the Kubernetes cluster and steve | ||
| # | ||
| # Kubernetes: KUBECONFIG=<path to kubeconfig> | ||
| # Steve URL: <steve API endpoint> | ||
| # SQL cache database: <path to sqlite database> | ||
| # | ||
| ########################### | ||
| ``` | ||
|
|
||
| You can then use this information to interact with the Kubernetes cluster and the steve API. | ||
|
|
||
| ## Adding new tests | ||
|
|
||
| The integration tests are written using the `testify/suite` package. The main suite is `IntegrationSuite` in `integration_test.go`. | ||
|
|
||
| Tests are data-driven and rely on `.test.yaml` files located in the `testdata` directory. These YAML files contain both the Kubernetes resources to apply and the configuration for the test assertions. | ||
|
|
||
| To add a new test scenario, you can follow the example of `column_test.go` and `testdata/columns/`: | ||
|
|
||
| 1. Create a new `my_feature_test.go` file in the `tests/` directory. | ||
| 2. Create a new directory `testdata/my_feature/`. | ||
| 3. Add a new test function to the `IntegrationSuite`, for example `TestMyFeature`, in your new Go file. | ||
| 4. In this function, you will typically: | ||
| - Set up a `httptest.NewServer` with the steve API handler. | ||
| - Find your test scenarios by looking for `.test.yaml` files in `testdata/my_feature/`. | ||
| - For each scenario, run a subtest. | ||
| 5. Each subtest should: | ||
| - Parse the `.test.yaml` file. The file can contain a header with test configuration and Kubernetes objects separated by `---`. | ||
| - Apply the Kubernetes objects to the cluster. | ||
| - Make requests to the steve API. | ||
| - Assert that the responses are correct based on the test configuration. | ||
| - Ensure that `defer i.maybeStopAndDebug(baseURL)` is called to allow for debugging. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of moving this to an option in the CachefactoryOption struct so we can modify things per-gvk (fields, type hints, etc). But that would be in another PR. For now, the only other way I figured was making this public for the sake of modifying it in the tests. Not great, but does the job. Open to other suggestions though