From 0d9d97fc64bfb704f19951bb1006e69bcd99fbaa Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Mon, 22 Sep 2025 11:46:56 +1000 Subject: [PATCH] Clarify how acceptance tests should be run --- .github/copilot-instructions.md | 19 +++++++------------ .github/workflows/test.yml | 2 +- Makefile | 6 ++++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 7e340a86c..234be2e41 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,14 +1,9 @@ You will be tasked to fix an issue from an open-source repository. This is a Go based repository hosting a Terrform provider for the elastic stack (elasticsearch and kibana) APIs. This repo currently supports both [plugin framework](https://developer.hashicorp.com/terraform/plugin/framework/getting-started/code-walkthrough) and [sdkv2](https://developer.hashicorp.com/terraform/plugin/sdkv2) resources. Unless you're told otherwise, all new resources _must_ use the plugin framework. - - - Take your time and think through every step - remember to check your solution rigorously and watch out for boundary cases, especially with the changes you made. Your solution must be perfect. If not, continue working on it. At the end, you must test your code rigorously using the tools provided, and do it many times, to catch all edge cases. If it is not robust, iterate more and make it perfect. Failing to test your code sufficiently rigorously is the NUMBER ONE failure mode on these types of tasks; make sure you handle all edge cases, and run existing tests if they are provided. - Please see [README.md](../README.md) and the [CONTRIBUTING.md](../CONTRIBUTING.md) docs before getting started. - # Workflow ## High-Level Problem Solving Strategy @@ -57,11 +52,10 @@ Carefully read the issue and think hard about a plan to solve it before coding. - After each change, verify correctness by running relevant tests. - If tests fail, analyze failures and revise your patch. - Write additional tests if needed to capture important behaviors or edge cases. -- Ensure all tests pass before finalizing. +- NEVER accept acceptance tests that have been skipped due to environment issues; always ensure the environment is correctly set up and all tests run successfully. ### 6.1 Acceptance Testing Requirements -When running acceptance tests (`make testacc`), ensure the following: - +When running acceptance tests, ensure the following: - **Environment Variables** - The following environment variables are required for acceptance tests: - `ELASTICSEARCH_ENDPOINTS` (default: http://localhost:9200) @@ -69,15 +63,16 @@ When running acceptance tests (`make testacc`), ensure the following: - `ELASTICSEARCH_PASSWORD` (default: password) - `KIBANA_ENDPOINT` (default: http://localhost:5601) - `TF_ACC` (must be set to "1" to enable acceptance tests) -- **Ensure a valid environment if using `go test`** - Check if the required environment variables are set, if not use the defaults specified above. -- **Always finish with `make testacc`** - This will run all tests. Make sure all tests pass before considering a task complete. -- **Pre-set Environment Variables** - Default environment variables are configured in the Makefile. If these defaults are suitable for your testing environment, `make testacc` will work directly without additional setup -- **Docker Environment** - For isolated testing with guaranteed environment setup, use `make docker-testacc` which starts Elasticsearch and Kibana containers automatically +- **Run targeted tests using `go test`** - Ensure the required environment variables are explicitly defined when running targeted tests. Example: + ```bash + ELASTICSEARCH_ENDPOINTS=http://localhost:9200 ELASTICSEARCH_USERNAME=elastic ELASTICSEARCH_PASSWORD=password KIBANA_ENDPOINT=http://localhost:5601 TF_ACC=1 go test -v -run TestAccResourceName ./path/to/testfile.go + ``` ## 7. Final Verification - Confirm the root cause is fixed. - Review your solution for logic correctness and robustness. - Iterate until you are extremely confident the fix is complete and all tests pass. +- Run the acceptance tests for any changed resources. Ensure acceptance tests pass without any environment-related skips. Use `make testacc` to verify this, explicitly defining the required environment variables. - Run `make lint` to ensure any linting errors have not surfaced with your changes. This task may automatically correct any linting errors, and regenerate documentation. Include any changes in your commit. ## 8. Final Reflection and Additional Testing diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d2eec47b..5e23596ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,7 @@ jobs: terraform_wrapper: false - name: Lint - run: make lint + run: make check-lint test: name: Matrix Acceptance Test diff --git a/Makefile b/Makefile index d94bcf925..1e4f374e4 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,6 @@ build-ci: ## build the terraform provider .PHONY: build build: lint build-ci ## build the terraform provider - .PHONY: testacc testacc: ## Run acceptance tests TF_ACC=1 go test -v ./... -count $(ACCTEST_COUNT) -parallel $(ACCTEST_PARALLELISM) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) @@ -254,7 +253,10 @@ golangci-lint: .PHONY: lint -lint: setup golangci-lint check-fmt check-docs ## Run lints to check the spelling and common go patterns +lint: setup golangci-lint fmt docs-generate ## Run lints to check the spelling and common go patterns + +.PHONY: check-lint +check-lint: setup golangci-lint check-fmt check-docs .PHONY: fmt fmt: ## Format code