From b36c3b6e3c0639188653be3142e7243aa3503327 Mon Sep 17 00:00:00 2001 From: Natalie Perret <11332444+natalie-o-perret@users.noreply.github.com> Date: Fri, 22 May 2026 19:34:20 +0200 Subject: [PATCH 1/3] test(e2e): add local creds helper for API tests --- tests/e2e/local_test.go | 67 ++++++++++++++++++++++++++++++++ tests/e2e/testscript_api_test.go | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/local_test.go diff --git a/tests/e2e/local_test.go b/tests/e2e/local_test.go new file mode 100644 index 00000000..4525a028 --- /dev/null +++ b/tests/e2e/local_test.go @@ -0,0 +1,67 @@ +//go:build local_integration + +package e2e_test + +// Local dev only — use -tags=local_integration -account= + +import ( + "flag" + "os" + "strings" + "testing" +) + +var flagAccount = flag.String("account", "owner-production", "account name substring in exoscale.toml") + +func TestAPIComputeLocal(t *testing.T) { + loadLocalCreds(t) + runAPITestSuite(t, "scenarios/with-api/compute") +} + +func TestAPIDBaaSLocal(t *testing.T) { + loadLocalCreds(t) + runAPITestSuite(t, "scenarios/with-api/dbaas") +} + +func loadLocalCreds(t *testing.T) { + t.Helper() + + accountName := *flagAccount + + toml, err := os.ReadFile(os.ExpandEnv("$HOME/.config/exoscale/exoscale.toml")) + if err != nil { + t.Fatalf("loadLocalCreds: %v", err) + } + + blocks := strings.Split(string(toml), "[[accounts]]") + for _, block := range blocks[1:] { + if !strings.Contains(block, accountName) { + continue + } + key := tomlString(block, "key") + secret := tomlString(block, "secret") + zone := tomlString(block, "defaultZone") + if key == "" || secret == "" { + continue + } + t.Setenv("EXOSCALE_API_KEY", key) + t.Setenv("EXOSCALE_API_SECRET", secret) + if zone != "" { + t.Setenv("EXOSCALE_ZONE", zone) + } + return + } + + t.Fatalf("loadLocalCreds: no account matching %q in exoscale.toml", accountName) +} + +func tomlString(block, key string) string { + prefix := key + " = '" + for _, line := range strings.Split(block, "\n") { + line = strings.TrimSpace(line) + if after, ok := strings.CutPrefix(line, prefix); ok { + return strings.TrimSuffix(after, "'") + } + } + return "" +} diff --git a/tests/e2e/testscript_api_test.go b/tests/e2e/testscript_api_test.go index 64357a23..e643e972 100644 --- a/tests/e2e/testscript_api_test.go +++ b/tests/e2e/testscript_api_test.go @@ -1,4 +1,4 @@ -//go:build api +//go:build api || local_integration package e2e_test From 4b1cb6e04745ec1bf47aa4634cd720d5f48594bb Mon Sep 17 00:00:00 2001 From: Natalie Perret <11332444+natalie-o-perret@users.noreply.github.com> Date: Fri, 22 May 2026 19:50:43 +0200 Subject: [PATCH 2/3] docs(e2e): update scenarios README with current test commands --- tests/e2e/scenarios/README.md | 71 ++++++++++++++++------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/tests/e2e/scenarios/README.md b/tests/e2e/scenarios/README.md index 3ffdb25d..f74aae90 100644 --- a/tests/e2e/scenarios/README.md +++ b/tests/e2e/scenarios/README.md @@ -1,62 +1,55 @@ # E2E Testscript Scenarios -This directory contains testscript scenarios for end-to-end testing the Exoscale CLI. +Testscript scenarios for end-to-end testing the Exoscale CLI. ## Directory Structure -- **without-api/**: Test scenarios that don't require API access (run by default) -- **with-api/**: Test scenarios that require API access (run with `-tags=api`) - -## Current Scenarios - -### Tests Without API (scenarios/without-api/) - -- **basic_no_api.txtar**: Tests basic CLI functionality without API access (version, help commands) -- **config_isolated.txtar**: Tests config file isolation using `XDG_CONFIG_HOME` - -### Tests With API (scenarios/with-api/) - -No API test scenarios yet. These will be added in a future PR. +- **without-api/**: No API access required, runs by default +- **with-api/compute/**: Compute API scenarios (`-tags=api`, `-run TestScriptsAPICompute`) +- **with-api/dbaas/**: DBaaS API scenarios (`-tags=api`, `-run TestScriptsAPIDBaaS`) ## Running Tests -Tests use the pre-built binary from the existing build pipeline. Build it first: +Build the binary first: ```bash -# Build the CLI binary (from repository root) make build +``` -# Run local tests only (default - no build tag needed) +### Without API (default) + +```bash cd tests/e2e go test -v +``` -# Run API tests only (requires API credentials) -cd tests/e2e -go test -v -tags=api +### With API (CI — env vars) -# Run all tests (local + API) +```bash cd tests/e2e -go test -v -tags=api +EXOSCALE_API_KEY=... EXOSCALE_API_SECRET=... \ + go test -v -tags=api -timeout 30m -run TestScriptsAPICompute ``` -## Using Build Tags - -The test suite uses Go build tags to separate local tests from API tests: - -- **Local tests** (`testscript_local_test.go`): No build tag, runs by default -- **API tests** (`testscript_api_test.go`): Requires `-tags=api` build tag +```bash +cd tests/e2e +EXOSCALE_API_KEY=... EXOSCALE_API_SECRET=... \ + go test -v -tags=api -timeout 30m -run TestScriptsAPIDBaaS +``` -This approach is more maintainable than regex filtering and follows Go best practices. +### With API (local — reads from exoscale.toml) -## Future Work +```bash +cd tests/e2e +go test -v -tags=local_integration -timeout 30m \ + -run TestAPIComputeLocal -account= +``` -**TODO**: API-based tests will be added in a separate PR to `scenarios/with-api/`. These will require: -- Organization test account setup -- Proper API credentials configuration (`EXOSCALE_API_KEY`, `EXOSCALE_API_SECRET`) -- Test scenarios covering: - - Block storage operations (create, resize, snapshot, delete) - - Compute instance operations - - Network resources - - Other API-dependent features +```bash +cd tests/e2e +go test -v -tags=local_integration -timeout 30m \ + -run TestAPIDBaaSLocal -account= +``` -The CI workflow is already configured to run API tests on the master branch when credentials are available. +`-account` matches a substring of the account name in +`~/.config/exoscale/exoscale.toml`. Defaults to `owner-production`. From d4855a698f9b2ea6860ee1f12f8be764aac010fe Mon Sep 17 00:00:00 2001 From: Natalie Perret <11332444+natalie-o-perret@users.noreply.github.com> Date: Fri, 22 May 2026 19:52:00 +0200 Subject: [PATCH 3/3] docs(e2e): remove em dashes --- tests/e2e/scenarios/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/scenarios/README.md b/tests/e2e/scenarios/README.md index f74aae90..1fc991f0 100644 --- a/tests/e2e/scenarios/README.md +++ b/tests/e2e/scenarios/README.md @@ -23,7 +23,7 @@ cd tests/e2e go test -v ``` -### With API (CI — env vars) +### With API (CI, env vars) ```bash cd tests/e2e @@ -37,7 +37,7 @@ EXOSCALE_API_KEY=... EXOSCALE_API_SECRET=... \ go test -v -tags=api -timeout 30m -run TestScriptsAPIDBaaS ``` -### With API (local — reads from exoscale.toml) +### With API (local, reads from exoscale.toml) ```bash cd tests/e2e