(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestApplySchema(t *testing.T) { |
| 21 | schema := &jsonschema.Schema{ |
| 22 | Type: "object", |
| 23 | Properties: map[string]*jsonschema.Schema{ |
| 24 | "x": {Type: "integer", Default: json.RawMessage("3")}, |
| 25 | }, |
| 26 | } |
| 27 | resolved, err := schema.Resolve(&jsonschema.ResolveOptions{ValidateDefaults: true}) |
| 28 | if err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | |
| 32 | type S struct { |
| 33 | X int `json:"x"` |
| 34 | } |
| 35 | |
| 36 | for _, tt := range []struct { |
| 37 | data string |
| 38 | v any |
| 39 | want any |
| 40 | }{ |
| 41 | {`{"x": 1}`, new(S), &S{X: 1}}, |
| 42 | {`{}`, new(S), &S{X: 3}}, // default applied |
| 43 | {`{"x": 0}`, new(S), &S{X: 0}}, |
| 44 | {`{"x": 1}`, new(map[string]any), &map[string]any{"x": 1.0}}, |
| 45 | {`{}`, new(map[string]any), &map[string]any{"x": 3.0}}, // default applied |
| 46 | {`{"x": 0}`, new(map[string]any), &map[string]any{"x": 0.0}}, |
| 47 | } { |
| 48 | raw := json.RawMessage(tt.data) |
| 49 | raw, err = applySchema(raw, resolved) |
| 50 | if err != nil { |
| 51 | t.Fatal(err) |
| 52 | } |
| 53 | if err := json.Unmarshal(raw, &tt.v); err != nil { |
| 54 | t.Fatal(err) |
| 55 | } |
| 56 | if !reflect.DeepEqual(tt.v, tt.want) { |
| 57 | t.Errorf("got %#v, want %#v", tt.v, tt.want) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestToolErrorHandling(t *testing.T) { |
| 63 | // Construct server and add both tools at the top level |
nothing calls this directly
no test coverage detected
searching dependent graphs…