···
-
func TestGenerateCommunityDID(t *testing.T) {
-
name: "generates did:plc in dev mode",
-
plcDirectoryURL: "https://plc.directory",
-
name: "generates did:plc in prod mode",
-
plcDirectoryURL: "https://plc.directory",
-
for _, tt := range tests {
-
t.Run(tt.name, func(t *testing.T) {
-
g := NewGenerator(tt.isDevEnv, tt.plcDirectoryURL)
-
did, err := g.GenerateCommunityDID()
-
t.Fatalf("GenerateCommunityDID() error = %v", err)
-
if !strings.HasPrefix(did, tt.want) {
-
t.Errorf("GenerateCommunityDID() = %v, want prefix %v", did, tt.want)
-
// Verify it's a valid DID
-
t.Errorf("Generated DID failed validation: %v", did)
-
func TestGenerateCommunityDID_Uniqueness(t *testing.T) {
-
g := NewGenerator(true, "https://plc.directory")
-
// Generate 100 DIDs and ensure they're all unique
-
dids := make(map[string]bool)
-
for i := 0; i < 100; i++ {
-
did, err := g.GenerateCommunityDID()
-
t.Fatalf("GenerateCommunityDID() error = %v", err)
-
t.Errorf("Duplicate DID generated: %v", did)
-
func TestValidateDID(t *testing.T) {
-
did: "did:plc:z72i7hdynmk6r22z27h6tvur",
-
name: "valid did:plc with base32",
-
did: "did:plc:abc123xyz",
-
did: "did:web:coves.social",
-
name: "valid did:web with path",
-
did: "did:web:coves.social:community:gaming",
-
name: "invalid: missing prefix",
-
name: "invalid: missing method",
-
name: "invalid: missing identifier",
-
name: "invalid: only did",
-
name: "invalid: empty string",
-
for _, tt := range tests {
-
t.Run(tt.name, func(t *testing.T) {
-
if got := ValidateDID(tt.did); got != tt.want {
-
t.Errorf("ValidateDID(%v) = %v, want %v", tt.did, got, tt.want)