|
| 1 | +package tool |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func schemaProps(t *testing.T, params map[string]interface{}) map[string]interface{} { |
| 6 | + t.Helper() |
| 7 | + props, ok := params["properties"].(map[string]interface{}) |
| 8 | + if !ok { |
| 9 | + t.Fatal("properties missing") |
| 10 | + } |
| 11 | + return props |
| 12 | +} |
| 13 | + |
| 14 | +func TestGlobSchemaProvider(t *testing.T) { |
| 15 | + var _ SchemaProvider = GlobTool{} |
| 16 | + props := schemaProps(t, GlobTool{}.Parameters()) |
| 17 | + if props["pattern"].(map[string]interface{})["type"] != "string" { |
| 18 | + t.Fatal("pattern type wrong") |
| 19 | + } |
| 20 | + if props["path"].(map[string]interface{})["type"] != "string" { |
| 21 | + t.Fatal("path type wrong") |
| 22 | + } |
| 23 | + req, _ := GlobTool{}.Parameters()["required"].([]string) |
| 24 | + if len(req) != 1 || req[0] != "pattern" { |
| 25 | + t.Fatalf("required = %v, want [pattern]", GlobTool{}.Parameters()["required"]) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +func TestLSSchemaProvider(t *testing.T) { |
| 30 | + var _ SchemaProvider = LSTool{} |
| 31 | + props := schemaProps(t, LSTool{}.Parameters()) |
| 32 | + ignore, ok := props["ignore"].(map[string]interface{}) |
| 33 | + if !ok || ignore["type"] != "array" { |
| 34 | + t.Fatalf("ignore prop = %v, want array type", props["ignore"]) |
| 35 | + } |
| 36 | + items, ok := ignore["items"].(map[string]interface{}) |
| 37 | + if !ok || items["type"] != "string" { |
| 38 | + t.Fatalf("ignore items = %v, want string type", ignore["items"]) |
| 39 | + } |
| 40 | + _, hasRequired := LSTool{}.Parameters()["required"] |
| 41 | + if hasRequired { |
| 42 | + t.Fatalf("LS has no required fields, got %v", LSTool{}.Parameters()["required"]) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +func TestGrepSchemaProvider(t *testing.T) { |
| 47 | + var _ SchemaProvider = GrepTool{} |
| 48 | + props := schemaProps(t, GrepTool{}.Parameters()) |
| 49 | + for _, f := range []string{"pattern", "path", "include"} { |
| 50 | + if props[f].(map[string]interface{})["type"] != "string" { |
| 51 | + t.Fatalf("%s type wrong", f) |
| 52 | + } |
| 53 | + } |
| 54 | + req, _ := GrepTool{}.Parameters()["required"].([]string) |
| 55 | + if len(req) != 1 || req[0] != "pattern" { |
| 56 | + t.Fatalf("required = %v, want [pattern]", GrepTool{}.Parameters()["required"]) |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +func TestSkillSchemaProvider(t *testing.T) { |
| 61 | + var _ SchemaProvider = SkillTool{} |
| 62 | + props := schemaProps(t, SkillTool{}.Parameters()) |
| 63 | + if props["skill"].(map[string]interface{})["type"] != "string" { |
| 64 | + t.Fatal("skill type wrong") |
| 65 | + } |
| 66 | + _, hasRequired := SkillTool{}.Parameters()["required"] |
| 67 | + if hasRequired { |
| 68 | + t.Fatalf("Skill has no required fields, got %v", SkillTool{}.Parameters()["required"]) |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +func TestScreenshotSchemaProvider(t *testing.T) { |
| 73 | + var _ SchemaProvider = ScreenshotTool{} |
| 74 | + props := schemaProps(t, ScreenshotTool{}.Parameters()) |
| 75 | + if props["url"].(map[string]interface{})["type"] != "string" { |
| 76 | + t.Fatal("url type wrong") |
| 77 | + } |
| 78 | + if props["width"].(map[string]interface{})["type"] != "number" { |
| 79 | + t.Fatal("width type wrong") |
| 80 | + } |
| 81 | + req, _ := ScreenshotTool{}.Parameters()["required"].([]string) |
| 82 | + if len(req) != 1 || req[0] != "url" { |
| 83 | + t.Fatalf("required = %v, want [url]", ScreenshotTool{}.Parameters()["required"]) |
| 84 | + } |
| 85 | +} |
0 commit comments