Test the version commands against a KV v2 mount - #18
Conversation
The fake spoke version 1 only, while real Vault defaults to version 2, so nothing behind a version history could be tested. Add a second constructor selecting a version 2 mount, backed by a per-path version list and the data, metadata, delete, undelete and destroy endpoints. Correct the mount discovery body while here. The client reads the mount out of data.secret, so the old shape decoded to an empty map and reported version 1 by falling through rather than by saying so.
versions, undelete --all and a versioned get had no test of their success paths, only of the arguments they reject.
The version tests seeded history directly, so the write half of the v2 mount went unexercised: set appending a version rather than replacing a value, and revert writing an old version forward.
|
Added a third commit covering the write half of the v2 mount. The original tests seeded version history directly through the helpers, so One finding worth recording, since it contradicts a plausible-sounding concern
|
safe versions,safe undelete --all, andsafe get path^Nhad no test oftheir success paths — only of the arguments they reject. The reason is that the
internal/clifake Vault spoke KV version 1, and version history only exists ona version 2 mount. Real
vault server -devdefaults to version 2, so thecommands most dependent on versions were the ones tests could not reach.
I flagged this gap in #15, where the two version-command fixes had to rest on
live runs rather than tests. This closes it.
The fake
newCLIFakeV2gives a version 2 mount;newCLIFakeis untouched and stillgives version 1. Version 2 splits a secret across
data,metadata,delete,undelete, anddestroy, and keeps a per-path version list where a version canbe alive, deleted (reversible), or destroyed (not). Seeding helpers —
setV2,deleteV2,destroyV2— and aversionStatesaccessor for assertions.The endpoint shapes are taken from the vaultkv client source rather than guessed,
including the detail that a deleted version returns 404 with its metadata still
attached.
Mount discovery was also wrong, and the second commit fixes it. The client
reads the mount out of
data.secret; the fake served it one level up, so thestruct decoded to an empty map and the client reported version 1 by falling
through the nil check rather than by being told. The old behaviour was correct
by accident. All 17 existing
newCLIFakecallers still pass.The tests
Nine cases: every version and state listed by
versions;undelete --allreviving every deleted version while leaving destroyed ones alone;
getreadinga specific version, with
^0and a bare path both meaning latest; and a deletedversion refusing to be read.
Two of them pin #15 directly. I verified they fail without it by reverting
those two fixes and re-running:
The second is the important one — that bug was a silent no-op that still exited
zero, which is exactly the kind that a test has to catch because a human running
the command will not.
I mutation-tested the rest too: making
Vault.Readignore the requested versionfails the
gettest with= "two", want "one", so it is genuinely exercisingversion selection rather than passing by construction.
make checkandgo test -race ./internal/cli/both pass.Scope
Tests only — no production code changes.
This covers the
internal/clifake. Thepkg/vaultfake is still version 1only; extending it the same way would benefit the
tree/paths/getunittests there, and is a reasonable follow-up rather than something to fold in here.