From 790731f9815fc238e2a6b93079b3b48489525520 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 22 Aug 2024 17:42:19 +0200 Subject: [PATCH] remove generic schema test --- bundle/schema/schema_test.go | 229 +---------------------------------- 1 file changed, 1 insertion(+), 228 deletions(-) diff --git a/bundle/schema/schema_test.go b/bundle/schema/schema_test.go index 3eab7ca7..277d5a8e 100644 --- a/bundle/schema/schema_test.go +++ b/bundle/schema/schema_test.go @@ -12,234 +12,7 @@ import ( // TODO: Add a test that checks the primitive overrides for reference regexs work. // Basically that the custom override for bundle regex works. - -func TestGenericSchema(t *testing.T) { - type Person struct { - Name string `json:"name"` - Age int `json:"age,omitempty"` - } - - type Plot struct { - Stakes []string `json:"stakes"` - Deaths []Person `json:"deaths"` - Murders map[string]Person `json:"murders"` - } - - type Wedding struct { - Hidden string `json:","` - Groom Person `json:"groom"` - Bride Person `json:"bride"` - Plots []Plot `json:"plots"` - } - - type Story struct { - Hero *Person `json:"hero"` - Villian Person `json:"villian,omitempty"` - Weddings []Wedding `json:"weddings"` - } - - elem := Story{} - - schema, err := New(reflect.TypeOf(elem), nil) - assert.NoError(t, err) - - jsonSchema, err := json.MarshalIndent(schema, " ", " ") - assert.NoError(t, err) - - expected := - `{ - "type": "object", - "properties": { - "hero": { - "type": "object", - "properties": { - "age": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string", - "pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" - } - ] - }, - "name": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "name" - ] - }, - "villian": { - "type": "object", - "properties": { - "age": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string", - "pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" - } - ] - }, - "name": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "name" - ] - }, - "weddings": { - "type": "array", - "items": { - "type": "object", - "properties": { - "bride": { - "type": "object", - "properties": { - "age": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string", - "pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" - } - ] - }, - "name": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "name" - ] - }, - "groom": { - "type": "object", - "properties": { - "age": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string", - "pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" - } - ] - }, - "name": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "name" - ] - }, - "plots": { - "type": "array", - "items": { - "type": "object", - "properties": { - "deaths": { - "type": "array", - "items": { - "type": "object", - "properties": { - "age": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string", - "pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" - } - ] - }, - "name": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "name" - ] - } - }, - "murders": { - "type": "object", - "additionalProperties": { - "type": "object", - "properties": { - "age": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string", - "pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}" - } - ] - }, - "name": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "name" - ] - } - }, - "stakes": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "additionalProperties": false, - "required": [ - "stakes", - "deaths", - "murders" - ] - } - } - }, - "additionalProperties": false, - "required": [ - "groom", - "bride", - "plots" - ] - } - } - }, - "additionalProperties": false, - "required": [ - "hero", - "weddings" - ] - }` - - t.Log("[DEBUG] actual: ", string(jsonSchema)) - t.Log("[DEBUG] expected: ", expected) - assert.Equal(t, expected, string(jsonSchema)) -} +// TODO: Add a bundle of end to end tests, that both fail and pass the schema validation. func TestDocIngestionForObject(t *testing.T) { docs := &Docs{