summaryrefslogtreecommitdiff
path: root/internal/keepass/keepass_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-18 16:26:33 +0300
committerPaul Buetow <paul@buetow.org>2026-04-18 16:26:33 +0300
commit7292a5db4e96ffeb30697ce3308d47777bf7c2f5 (patch)
tree82df398206ab89487c0d7608068a31c5cbf97b89 /internal/keepass/keepass_test.go
parent667bf24a8ac2c2b4c4f9befd7f77b22f0a156a27 (diff)
keepass: fix parseContent doc comment and add importBytes ctx note
- Replace the inaccurate "Go compiler can optimise away" claim in parseContent's doc with an accurate explanation: callers that already hold a string pass it directly, while []byte callers make a single explicit conversion at the call site, keeping the conversion visible rather than hidden inside the function (100 Go Mistakes #40). - Add a comment in importBytes explaining why ctx is not threaded into addAttachment or addTextEntry: both are synchronous, purely in-memory operations with no I/O or blocking calls that could respect cancellation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/keepass/keepass_test.go')
-rw-r--r--internal/keepass/keepass_test.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/internal/keepass/keepass_test.go b/internal/keepass/keepass_test.go
index 5a87514..8db2ae4 100644
--- a/internal/keepass/keepass_test.go
+++ b/internal/keepass/keepass_test.go
@@ -640,7 +640,8 @@ func TestSearchActionWithActionFn(t *testing.T) {
}
// Verify the password is extractable via parseContent (the actual paste path
// in the CLI would do this and send only the password to the clipboard).
- pw, _, _, _ := parseContent(captured)
+ // parseContent accepts string; convert captured []byte once here.
+ pw, _, _, _ := parseContent(string(captured))
if pw != "secret" {
t.Errorf("parseContent from paste content: got password %q, want %q", pw, "secret")
}
@@ -840,7 +841,8 @@ func TestImportForce(t *testing.T) {
if err != nil {
t.Fatalf("LoadData after forced import: %v", err)
}
- pw, _, _, _ := parseContent(d.Content)
+ // parseContent accepts string; d.Content is []byte so convert once.
+ pw, _, _, _ := parseContent(string(d.Content))
if pw != "replaced" {
t.Errorf("password after forced import = %q; want %q", pw, "replaced")
}
@@ -946,7 +948,8 @@ func TestFormatParseRoundtrip(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
content := formatContent(tc.password, tc.user, tc.url, tc.notes)
- gotPw, gotUser, gotURL, gotNotes := parseContent(content)
+ // parseContent accepts string; formatContent returns []byte, so convert once.
+ gotPw, gotUser, gotURL, gotNotes := parseContent(string(content))
if gotPw != tc.password {
t.Errorf("password: got %q, want %q", gotPw, tc.password)
}