chore: initial release v0.1.0
forge-toolkit: хелперы для разработки MCP-серверов на Go. - toolkit: args/schema/result/env/probe/server - toolkit/validate: валидаторы синтаксиса - configreload: live-reload конфига по контент-хэшу - docs: ARCHITECTURE, quickstart, mcp-contract - template/ и examples/hello-tool/ - CI (Gitea Actions), лицензия Apache-2.0
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package toolkit
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSchemaNilPropertiesBecomesObject(t *testing.T) {
|
||||
s := Schema(nil, nil)
|
||||
props, ok := s["properties"].(map[string]any)
|
||||
if !ok || props == nil {
|
||||
t.Fatalf("properties = %#v, want non-nil object", s["properties"])
|
||||
}
|
||||
if _, has := s["required"]; has {
|
||||
t.Error("required must be omitted when empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchemaRequired(t *testing.T) {
|
||||
s := Schema(map[string]any{"a": StrProps("A", true)}, []string{"a"})
|
||||
req, ok := s["required"].([]string)
|
||||
if !ok || len(req) != 1 || req[0] != "a" {
|
||||
t.Fatalf("required = %#v", s["required"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrPropsEnum(t *testing.T) {
|
||||
s := StrProps("mode", true, "a", "b")
|
||||
enum, ok := s["enum"].([]string)
|
||||
if !ok || len(enum) != 2 {
|
||||
t.Fatalf("enum = %#v", s["enum"])
|
||||
}
|
||||
if StrProps("x", false)["enum"] != nil {
|
||||
t.Error("no enum expected without values")
|
||||
}
|
||||
}
|
||||
|
||||
func TestObjectProps(t *testing.T) {
|
||||
s := ObjectProps("headers", false)
|
||||
if s["type"] != "object" {
|
||||
t.Errorf("type = %v", s["type"])
|
||||
}
|
||||
if s["additionalProperties"] == nil {
|
||||
t.Error("additionalProperties must be set")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user