Skip to content

Commit 71f6f01

Browse files
committed
test(commands): pin root-detection dispatch and kubeconfig-bytes contracts
Add contract_root_dispatch_test.go pinning the layer that decides which directory becomes Config.RootDir at command-startup time (file flag -> template flag -> CWD), the talosconfig-path resolution, and the in-memory kubeconfig endpoint rewriter used by rotate-CA. Coverage: - getFlagValues: non-persistent and persistent StringSlice flags, absent flag returns non-nil empty slice (so callers can range without a guard), registered-but-unset returns empty. - detectRootFromFiles / detectRootFromTemplates: empty input yields ('', nil) so callers fall through; positive case under a real project root resolves to that root's abs path. - detectRootFromCWD walks up from CWD; macOS /var/folders symlink resolution handled via filepath.EvalSymlinks fallback. - checkRootConflict: no-op when --root not explicit, no error when explicit matches detected, error names BOTH paths on conflict (guides operator to either drop --root or move files). - DetectAndSetRoot: -f flag wins over CWD; files in two different roots is an explicit error; no flags + no markers leaves Config.RootDir untouched. - DetectAndSetRootFromFiles: happy-path file under root sets Config.RootDir; empty input falls back to CWD detection; --root explicit + files in a different root errors with 'conflicting' substring. - EnsureTalosconfigPath: no-op when --talosconfig is explicit; defaults to <RootDir>/talosconfig when nothing else set; Chart.yaml-supplied relative path anchored to RootDir; absolute path preserved as-is. - updateKubeconfigEndpoint: rewrites every cluster's server: to https://<host>:6443 (drops protocol/port from input, hardcodes 6443); malformed bytes surface parse error. Each test that mutates package-level Config / GlobalArgs uses withConfigSnapshot to capture and restore prior state, so tests can run in any order without leaking. Coverage: pkg/commands 29.7% -> 35.0%. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 90eb54a commit 71f6f01

1 file changed

Lines changed: 527 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)