Skip to content

test(e2e): local creds helper for API tests#837

Merged
natalie-o-perret merged 3 commits into
masterfrom
feat/e2e-local-creds
Jun 3, 2026
Merged

test(e2e): local creds helper for API tests#837
natalie-o-perret merged 3 commits into
masterfrom
feat/e2e-local-creds

Conversation

@natalie-o-perret
Copy link
Copy Markdown
Contributor

@natalie-o-perret natalie-o-perret commented May 22, 2026

Adds tests/e2e/local_test.go (build tag: local, never compiled on CI).

Reads credentials from ~/.config/exoscale/exoscale.toml via -account flag and injects them with t.Setenv, never printed.

E.g.,

go test -tags='api local' -timeout 30m -run TestAPIComputeLocal . -account=my-user-owner

@natalie-o-perret natalie-o-perret marked this pull request as ready for review June 2, 2026 16:03
@natalie-o-perret
Copy link
Copy Markdown
Contributor Author

[SC-182794]

@natalie-o-perret natalie-o-perret added the enhancement New feature or request label Jun 3, 2026
@natalie-o-perret natalie-o-perret self-assigned this Jun 3, 2026
@natalie-o-perret natalie-o-perret merged commit ec54722 into master Jun 3, 2026
6 checks passed
@natalie-o-perret natalie-o-perret deleted the feat/e2e-local-creds branch June 3, 2026 14:05
natalie-o-perret added a commit to exoscale/terraform-provider-exoscale that referenced this pull request Jun 4, 2026
Add a build-tagged entry point to every acceptance test package so
contributors can run real-infrastructure tests without exporting
EXOSCALE_API_KEY / EXOSCALE_API_SECRET into the shell, and without
remembering to set TF_ACC=1.

Mirrors exoscale/cli#837. Credentials are read from
$HOME/.config/exoscale/exoscale.toml (same file the CLI uses) and
injected via t.Setenv, scoped to the test. LoadLocalCreds also defaults
TF_ACC to "1" when unset; a pre-set value is respected.

- pkg/testutils/localcreds.go: LoadLocalCreds(t, account) helper. No
  build tag, but only invoked from build-tagged _test.go files, so CI
  never sees it.
- pkg/resources/<pkg>/local_test.go (build local_integration): one
  TestXxxLocal per package that loads creds and forwards to the
  existing TestXxx entry point. 9 packages covered; the legacy
  exoscale/ package has no single entry point and is left out
  (callers can still use LoadLocalCreds directly there).

Usage:
  go test -tags=local_integration -run TestDatabaseLocal \
    -account=owner-production -timeout 60m ./pkg/resources/database/
natalie-o-perret added a commit to exoscale/terraform-provider-exoscale that referenced this pull request Jun 4, 2026
Add a build-tagged entry point to every acceptance test package so
contributors can run real-infrastructure tests without exporting
EXOSCALE_API_KEY / EXOSCALE_API_SECRET into the shell, and without
remembering to set TF_ACC=1.

Mirrors exoscale/cli#837. Credentials are read from
$HOME/.config/exoscale/exoscale.toml (same file the CLI uses) and
injected via t.Setenv, scoped to the test. LoadLocalCreds also defaults
TF_ACC to "1" when unset; a pre-set value is respected.

- pkg/testutils/localcreds.go: LoadLocalCreds(t, account) helper. No
  build tag, but only invoked from build-tagged _test.go files, so CI
  never sees it.
- pkg/resources/<pkg>/local_test.go (build local_integration): one
  TestXxxLocal per package that loads creds and forwards to the
  existing TestXxx entry point. 9 packages covered; the legacy
  exoscale/ package has no single entry point and is left out
  (callers can still use LoadLocalCreds directly there).

Usage:
  go test -tags=local_integration -run TestDatabaseLocal \
    -account=owner-production -timeout 60m ./pkg/resources/database/
natalie-o-perret added a commit to exoscale/terraform-provider-exoscale that referenced this pull request Jun 5, 2026
# Description

Local helper for running acceptance tests against real infra. Mirrors
exoscale/cli#837. Reads `~/.config/exoscale/exoscale.toml`, sets the
creds via `t.Setenv`, defaults `TF_ACC=1` (pre-set is respected).

```sh
go test -tags=local_integration -run TestDatabaseLocal \
  -account=owner-production -timeout 60m ./pkg/resources/database/
```

- `pkg/testutils/localcreds.go`: `LoadLocalCreds(t, account)`.
- 9 `pkg/resources/<pkg>/local_test.go` (build `local_integration`):
`TestXxxLocal` per package, wraps the existing `TestXxx`. Legacy
`exoscale/` left out, no single entry.
- `README.md`: short note in Contributing pointing at the helper, so new
contributors know they don't need to export creds by hand.

Build, vet, gofmt, unit tests clean. Smoke tested with a fake
`exoscale.toml`, env vars land correctly, `TF_ACC` default and override
both work.

## Checklist
(For exoscale contributors)

* [ ] Changelog updated (under *Unreleased* block)
* [ ] Acceptance tests OK
* [ ] For a new resource, datasource or new attributes: acceptance test
added/updated

## Testing

`make test` passes. No real-infra run, no creds in this env.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant