MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestPublicJSONSchemaFiles

Function TestPublicJSONSchemaFiles

cmd/json_contract_test.go:192–245  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

190}
191
192func TestPublicJSONSchemaFiles(t *testing.T) {
193 tests := []struct {
194 file string
195 ok bool
196 required []string
197 properties []string
198 }{
199 {
200 file: "../docs/json-schema/v1/success.schema.json",
201 ok: true,
202 required: []string{"ok", "schema_version", "command", "input", "results", "warnings"},
203 properties: []string{"ok", "schema_version", "command", "input", "results", "warnings"},
204 },
205 {
206 file: "../docs/json-schema/v1/error.schema.json",
207 ok: false,
208 required: []string{"ok", "schema_version", "command", "error", "warnings"},
209 properties: []string{"ok", "schema_version", "command", "error", "warnings"},
210 },
211 }
212
213 for _, tt := range tests {
214 t.Run(tt.file, func(t *testing.T) {
215 schema := loadPublicJSONSchema(t, tt.file)
216 if schema.Schema == "" {
217 t.Fatalf("%s has no $schema", tt.file)
218 }
219 if schema.ID == "" {
220 t.Fatalf("%s has no $id", tt.file)
221 }
222 if schema.Type != "object" {
223 t.Fatalf("%s type = %q, want object", tt.file, schema.Type)
224 }
225 if got, want := schema.Properties["ok"].Const, tt.ok; got != want {
226 t.Fatalf("%s ok const = %v, want %v", tt.file, got, want)
227 }
228 if got, want := schema.Properties["schema_version"].Const, jsonSchemaVersion; got != want {
229 t.Fatalf("%s schema_version const = %v, want %v", tt.file, got, want)
230 }
231 assertStringSliceEqual(t, tt.file+" required", schema.Required, tt.required)
232 assertStringSliceEqual(t, tt.file+" properties", mapKeys(schema.Properties), tt.properties)
233 if tt.ok {
234 assertStringSliceEqual(t, tt.file+" result required", schema.Defs["result"].Required, []string{"status", "kind", "input", "result"})
235 } else {
236 errorSchema := schema.Properties["error"]
237 codeSchema := errorSchema.Properties["code"]
238 assertStringSliceEqual(t, tt.file+" error code enum", codeSchema.Enum, expectedJSONErrorCodes())
239 if _, ok := errorSchema.Properties["details"]; !ok {
240 t.Fatalf("%s error schema missing details property", tt.file)
241 }
242 }
243 })
244 }
245}
246
247func TestPublicJSONManifestSchemaFile(t *testing.T) {
248 schema := loadPublicJSONSchema(t, "../docs/json-schema/v1/manifest.schema.json")

Callers

nothing calls this directly

Calls 4

loadPublicJSONSchemaFunction · 0.85
assertStringSliceEqualFunction · 0.85
mapKeysFunction · 0.85
expectedJSONErrorCodesFunction · 0.85

Tested by

no test coverage detected