···
for _, filePath := range lexiconFiles {
// Convert file path to schema ID
// e.g., ../internal/atproto/lexicon/social/coves/actor/profile.json -> social.coves.actor.profile
-
relPath, _ := filepath.Rel(schemaPath, filePath)
relPath = strings.TrimSuffix(relPath, ".json")
schemaID := strings.ReplaceAll(relPath, string(filepath.Separator), ".")
t.Run(schemaID, func(t *testing.T) {
-
if _, err := catalog.Resolve(schemaID); err != nil {
-
t.Errorf("Failed to resolve schema %s: %v", schemaID, err)
···
// Test specific cross-references that should work
crossRefs := map[string]string{
-
"social.coves.richtext.facet#byteSlice": "byteSlice definition in facet schema",
"social.coves.actor.profile#geoLocation": "geoLocation definition in actor profile",
"social.coves.community.rules#rule": "rule definition in community rules",
···
// Test cases for ValidateRecord
-
recordData map[string]interface{}
name: "Valid actor profile",
···
recordType: "social.coves.community.profile",
recordData: map[string]interface{}{
"$type": "social.coves.community.profile",
"displayName": "Programming Community",
-
"creator": "did:plc:creator123",
"moderationType": "moderator",
"federatedFrom": "coves",
"createdAt": "2023-12-01T08:00:00Z",
···
name: "Valid post record",
recordType: "social.coves.post.record",
recordData: map[string]interface{}{
-
"$type": "social.coves.post.record",
-
"community": "did:plc:programming123",
-
"content": "This is a test post",
-
"createdAt": "2025-01-09T14:30:00Z",
···
name: "Invalid post record - invalid enum value",
recordType: "social.coves.post.record",
recordData: map[string]interface{}{
-
"$type": "social.coves.post.record",
-
"community": "did:plc:programming123",
-
"postType": "invalid-type",
-
"content": "This is a test post",
-
"createdAt": "2025-01-09T14:30:00Z",
errorContains: "string val not in required enum",
···
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := lexicon.ValidateRecord(&catalog, tt.recordData, tt.recordType, lexicon.AllowLenientDatetime)
t.Errorf("Expected validation to fail but it passed")
···
t.Errorf("Expected lenient validation to pass, got error: %v", err)
···
for _, filePath := range lexiconFiles {
// Convert file path to schema ID
// e.g., ../internal/atproto/lexicon/social/coves/actor/profile.json -> social.coves.actor.profile
+
relPath, err := filepath.Rel(schemaPath, filePath)
+
t.Fatalf("Failed to get relative path for %s: %v", filePath, err)
relPath = strings.TrimSuffix(relPath, ".json")
schemaID := strings.ReplaceAll(relPath, string(filepath.Separator), ".")
t.Run(schemaID, func(t *testing.T) {
+
if _, resolveErr := catalog.Resolve(schemaID); resolveErr != nil {
+
t.Errorf("Failed to resolve schema %s: %v", schemaID, resolveErr)
···
// Test specific cross-references that should work
crossRefs := map[string]string{
+
"social.coves.richtext.facet#byteSlice": "byteSlice definition in facet schema",
"social.coves.actor.profile#geoLocation": "geoLocation definition in actor profile",
"social.coves.community.rules#rule": "rule definition in community rules",
···
// Test cases for ValidateRecord
+
recordData map[string]interface{}
name: "Valid actor profile",
···
recordType: "social.coves.community.profile",
recordData: map[string]interface{}{
"$type": "social.coves.community.profile",
+
"handle": "programming.communities.coves.social",
"displayName": "Programming Community",
+
"createdBy": "did:plc:creator123",
+
"hostedBy": "did:plc:coves123",
+
"visibility": "public",
"moderationType": "moderator",
"federatedFrom": "coves",
"createdAt": "2023-12-01T08:00:00Z",
···
name: "Valid post record",
recordType: "social.coves.post.record",
recordData: map[string]interface{}{
+
"$type": "social.coves.post.record",
+
"community": "did:plc:programming123",
+
"content": "This is a test post",
+
"createdAt": "2025-01-09T14:30:00Z",
···
name: "Invalid post record - invalid enum value",
recordType: "social.coves.post.record",
recordData: map[string]interface{}{
+
"$type": "social.coves.post.record",
+
"community": "did:plc:programming123",
+
"postType": "invalid-type",
+
"content": "This is a test post",
+
"createdAt": "2025-01-09T14:30:00Z",
errorContains: "string val not in required enum",
···
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := lexicon.ValidateRecord(&catalog, tt.recordData, tt.recordType, lexicon.AllowLenientDatetime)
t.Errorf("Expected validation to fail but it passed")
···
t.Errorf("Expected lenient validation to pass, got error: %v", err)