zjncs opened a new pull request, #6208:
URL: https://github.com/apache/rocketmq-dashboard/pull/6208
### What
`rmqctl/internal/config` — `Validate` / `ValidateContext` /
`EnvironmentReference` and the `Save`/`Load` error paths had no direct test
(the existing `config_test.go` covers the round trip and `ResolveCredential`).
This adds 13 tests pinning the contract:
- **Normalize** replaces a nil context map with an empty one;
- **Validate**: blank context names are rejected; every missing context
field (`server`, `credential.accessKeyRef`, `credential.secretKeyRef`) is
rejected **by name, with the failing context named**; a dangling
`currentContext` is rejected while an empty one stays valid;
- **credential references must be `env:NAME`** with a valid environment
identifier (`env:_private` and `env:A_1` pass; `RMQ_AK`, `env:`,
`env:bad-name`, `env:9start`, `file:...` are rejected);
- **Load**: absent files load as the empty config; a directory never loads;
malformed YAML and invalid stored configs are rejected at load (a dangling
`currentContext` in the file is caught, not silently accepted);
- **Save**: an invalid config is rejected **without creating the file**; a
valid save **replaces atomically** — the second save fully replaces the first
and no `.rmqctl-config-*` temp file is left behind.
### Verification
- New tests on unmodified code: **13/13 passed** (`go test
./internal/config/ -count=1`), `go vet` clean.
- Discriminating mutations on config.go (7 tests red, 6 green):
- drop the `currentContext` existence check: the dangling-context tests at
load and at save red, and the atomic-replace test follows;
- invert the required-field check: the field-required and env-reference
tests red.
- config.go restored: full `./internal/config/` package **ok**.
### Collision check
Checked against all open PRs — no other PR touches
`rmqctl/internal/config/config.go` or adds `config_validation_test.go` (the
existing `config_test.go` is untouched).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]