···
8
-
func TestGenerateCommunityDID(t *testing.T) {
11
-
plcDirectoryURL string
16
-
name: "generates did:plc in dev mode",
18
-
plcDirectoryURL: "https://plc.directory",
22
-
name: "generates did:plc in prod mode",
24
-
plcDirectoryURL: "https://plc.directory",
29
-
for _, tt := range tests {
30
-
t.Run(tt.name, func(t *testing.T) {
31
-
g := NewGenerator(tt.isDevEnv, tt.plcDirectoryURL)
32
-
did, err := g.GenerateCommunityDID()
34
-
t.Fatalf("GenerateCommunityDID() error = %v", err)
37
-
if !strings.HasPrefix(did, tt.want) {
38
-
t.Errorf("GenerateCommunityDID() = %v, want prefix %v", did, tt.want)
41
-
// Verify it's a valid DID
42
-
if !ValidateDID(did) {
43
-
t.Errorf("Generated DID failed validation: %v", did)
49
-
func TestGenerateCommunityDID_Uniqueness(t *testing.T) {
50
-
g := NewGenerator(true, "https://plc.directory")
52
-
// Generate 100 DIDs and ensure they're all unique
53
-
dids := make(map[string]bool)
54
-
for i := 0; i < 100; i++ {
55
-
did, err := g.GenerateCommunityDID()
57
-
t.Fatalf("GenerateCommunityDID() error = %v", err)
61
-
t.Errorf("Duplicate DID generated: %v", did)
67
-
func TestValidateDID(t *testing.T) {
74
-
name: "valid did:plc",
75
-
did: "did:plc:z72i7hdynmk6r22z27h6tvur",
79
-
name: "valid did:plc with base32",
80
-
did: "did:plc:abc123xyz",
84
-
name: "valid did:web",
85
-
did: "did:web:coves.social",
89
-
name: "valid did:web with path",
90
-
did: "did:web:coves.social:community:gaming",
94
-
name: "invalid: missing prefix",
99
-
name: "invalid: missing method",
100
-
did: "did::abc123",
104
-
name: "invalid: missing identifier",
109
-
name: "invalid: only did",
114
-
name: "invalid: empty string",
120
-
for _, tt := range tests {
121
-
t.Run(tt.name, func(t *testing.T) {
122
-
if got := ValidateDID(tt.did); got != tt.want {
123
-
t.Errorf("ValidateDID(%v) = %v, want %v", tt.did, got, tt.want)