MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / TestStore_URLNormalization

Function TestStore_URLNormalization

internal/cli/credentials_test.go:303–322  ·  view source on GitHub ↗

TestStore_URLNormalization — trailing slashes and surrounding whitespace must canonicalize so http://x:7777 and http://x:7777/ hit the same bucket. cfg.BrowserURL() trims trailing slash; user-typed --url flags often don't.

(t *testing.T)

Source from the content-addressed store, hash-verified

301// the same bucket. cfg.BrowserURL() trims trailing slash; user-typed
302// --url flags often don't.
303func TestStore_URLNormalization(t *testing.T) {
304 store := newEmptyStore()
305 store.Set("http://x:7777/", &Credentials{Token: "with-slash"})
306
307 // Trailing slash variant should find the entry too.
308 if got := store.Get("http://x:7777"); got == nil || got.Token != "with-slash" {
309 t.Errorf("Get on slash-trimmed key: got %+v, want token=with-slash", got)
310 }
311 // As should a leading-whitespace variant.
312 if got := store.Get(" http://x:7777 "); got == nil {
313 t.Errorf("Get on whitespace variant returned nil")
314 }
315
316 // And only one entry should exist (Set with a different formatting
317 // of the same canonical URL must replace, not duplicate).
318 store.Set("http://x:7777", &Credentials{Token: "no-slash"})
319 if got := len(store.Credentials); got != 1 {
320 t.Errorf("expected 1 entry after canonical-equivalent Set, got %d", got)
321 }
322}
323
324// TestStore_Save_PreservesAllEntries — Save round-trips multiple
325// servers without losing any entries. Direct test of the multi-server

Callers

nothing calls this directly

Calls 3

newEmptyStoreFunction · 0.85
GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected