Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738package nixcache
import ( "strings" "testing")
func TestCacheName(t *testing.T) { if got, err := CacheName("did:plc:z72i7hdynmk6r22z27h6tvur"); err != nil || got != "plc-z72i7hdynmk6r22z27h6tvur" { t.Errorf("CacheName(plc) = %q, %v", got, err) } if got, err := CacheName(""); err == nil { t.Errorf("CacheName(\"\") = %q; want an error", got) }
dids := []string{ "did:web:example.com", "did:plc:UPPER", "did:plc:short", "did:plc:z72i7hdynmk6r22z27h6tvur-extra", "*", } seen := map[string]string{} for _, did := range dids { got, err := CacheName(did) if err != nil { t.Fatalf("CacheName(%q): %v", did, err) } if !strings.HasPrefix(got, "h-") || len(got) != 34 || !validName.MatchString(got) { t.Errorf("CacheName(%q) = %q; want valid h- and 32 chars", did, got) } if other, ok := seen[got]; ok { t.Errorf("CacheName(%q) collides with %q", did, other) } seen[got] = did }}