(t *testing.T)
| 26 | } |
| 27 | |
| 28 | func TestReadTool_InputSchema(t *testing.T) { |
| 29 | tool, err := NewReadTool(nil) |
| 30 | if err != nil { |
| 31 | t.Fatalf("Failed to create Read tool: %v", err) |
| 32 | } |
| 33 | |
| 34 | schema := tool.InputSchema() |
| 35 | if schema == nil { |
| 36 | t.Fatal("Input schema should not be nil") |
| 37 | } |
| 38 | |
| 39 | // 验证schema类型 |
| 40 | if schemaType, ok := schema["type"].(string); !ok || schemaType != "object" { |
| 41 | t.Errorf("Expected schema type 'object', got %v", schema["type"]) |
| 42 | } |
| 43 | |
| 44 | // 验证必需字段 |
| 45 | properties, ok := schema["properties"].(map[string]any) |
| 46 | if !ok { |
| 47 | t.Fatal("Properties should be a map") |
| 48 | } |
| 49 | |
| 50 | if _, exists := properties["file_path"]; !exists { |
| 51 | t.Error("file_path property should exist") |
| 52 | } |
| 53 | |
| 54 | required := schema["required"] |
| 55 | if required == nil { |
| 56 | t.Fatal("Required field should not be nil") |
| 57 | } |
| 58 | |
| 59 | // 尝试类型转换,但不强制要求特定类型 |
| 60 | switch req := required.(type) { |
| 61 | case []any: |
| 62 | if len(req) == 0 || req[0] != "file_path" { |
| 63 | t.Error("file_path should be required") |
| 64 | } |
| 65 | case []string: |
| 66 | if len(req) == 0 || req[0] != "file_path" { |
| 67 | t.Error("file_path should be required") |
| 68 | } |
| 69 | default: |
| 70 | t.Logf("Required field type: %T", required) |
| 71 | // 尝试转换为字符串切片进行检查 |
| 72 | if reqStr, ok := required.([]string); ok && len(reqStr) > 0 && reqStr[0] == "file_path" { |
| 73 | // 正确 |
| 74 | } else { |
| 75 | t.Error("file_path should be required") |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | func TestReadTool_Success(t *testing.T) { |
| 81 | tool, err := NewReadTool(nil) |
nothing calls this directly
no test coverage detected