Skip to content

test(kv): cover the invalid int error path in strict mode - #461

Merged
kke merged 1 commit into
k0sproject:mainfrom
magic-peach:test/kv-decoder-invalid-int
Sep 8, 2026
Merged

kke merged 1 commit into
k0sproject:mainfrom
magic-peach:test/kv-decoder-invalid-int

Conversation

@magic-peach

Copy link
Copy Markdown
Contributor

kv.Decoder's assignField has a parse int error branch that no test exercised. Adding a case for it also surfaced that Decode in non-strict mode (the default) silently discards assign errors, including this one, so the only way to actually observe the error is through Strict mode. This test uses Strict to reach it.

Test only, no production code changed.

Tested with go test ./kv/..., gofmt -l, and go vet ./kv/..., all clean.

assignField's parse int error was never exercised, and Decode in
non-strict mode silently swallows assign errors so the only way to
reach it is through Strict.

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is a focused test-only addition that correctly exercises a previously untested error branch without altering production behavior.

Pull request overview

Adds a regression test to ensure kv.Decoder exercises (and surfaces) the assignField integer parsing failure path, which is only observable when the decoder is in Strict mode.

Changes:

  • Added a new subtest that decodes an invalid int value (key4=notanumber) and asserts the resulting error contains "parse int".
  • Enables Strict() in that subtest so Decode returns assign/parse errors instead of discarding them in default (non-strict) mode.
File summaries
File Description
kv/decoder_test.go Adds a strict-mode test case that triggers and asserts the invalid-int parsing error path.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kke
kke merged commit 1530091 into k0sproject:main Sep 8, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants