Monorepo for Tangled
Something went wrong. Try again.
Go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115package userutil
import "testing"
func TestUnflattenDid(t *testing.T) { unflattenedMap := map[string]string{ "did-plc-abcdefghijklmnopqrstuvwxyz": "did:plc:abcdefghijklmnopqrstuvwxyz", "did-plc-1234567890": "did:plc:1234567890", "did-key-z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK": "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK", "did-plc-abcdefghi-jklmnopqr-stuvwxyz": "did:plc:abcdefghi-jklmnopqr-stuvwxyz", "plc-abcdefghijklmnopqrstuvwxyz": "plc-abcdefghijklmnopqrstuvwxyz", "didplc-abcdefghijklmnopqrstuvwxyz": "didplc-abcdefghijklmnopqrstuvwxyz", "": "", "did-": "did-", "did:plc:abcdefghijklmnopqrstuvwxyz": "did:plc:abcdefghijklmnopqrstuvwxyz", "did-invalid$format:something": "did-invalid$format:something", }
tests := []struct { name string input string expected string }{}
for _, tc := range isFlattenedDidTests { tests = append(tests, struct { name string input string expected string }{ name: tc.name, input: tc.input, expected: unflattenedMap[tc.input], }) }
for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { result := UnflattenDid(tc.input) if result != tc.expected { t.Errorf("unflattenDid(%q) = %q, want %q", tc.input, result, tc.expected) } }) }}
var isFlattenedDidTests = []struct { name string input string expected bool}{ { name: "valid flattened DID", input: "did-plc-abcdefghijklmnopqrstuvwxyz", expected: true, }, { name: "valid flattened DID with numbers", input: "did-plc-1234567890", expected: true, }, { name: "valid flattened DID with special characters", input: "did-key-z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK", expected: true, }, { name: "valid flattened DID with dashes", input: "did-plc-abcdefghi-jklmnopqr-stuvwxyz", expected: true, },
{ name: "doesn't start with did-", input: "plc-abcdefghijklmnopqrstuvwxyz", expected: false, }, { name: "no hyphen after did", input: "didplc-abcdefghijklmnopqrstuvwxyz", expected: false, }, { name: "empty string", input: "", expected: false, }, { name: "only did-", input: "did-", expected: false, }, { name: "standard DID format, not flattened", input: "did:plc:abcdefghijklmnopqrstuvwxyz", expected: false, }, { name: "invalid reconstructed DID format", input: "did-invalid$format:something", expected: false, },}
func TestIsFlattenedDid(t *testing.T) { for _, tc := range isFlattenedDidTests { t.Run(tc.name, func(t *testing.T) { result := IsFlattenedDid(tc.input) if result != tc.expected { t.Errorf("isFlattenedDid(%q) = %v, want %v", tc.input, result, tc.expected) } }) }}