mirror of https://github.com/databricks/cli.git
This commit is contained in:
parent
7db32fc211
commit
b89928513e
|
@ -388,141 +388,6 @@ func TestSliceOfStructSchema(t *testing.T) {
|
|||
assert.Equal(t, expected, string(jsonSchema))
|
||||
}
|
||||
|
||||
func TestEmbeddedStructSchema(t *testing.T) {
|
||||
type Location struct {
|
||||
Country string `json:"country"`
|
||||
State string `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
type Person struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,omitempty"`
|
||||
Home Location `json:"home"`
|
||||
}
|
||||
|
||||
type Plot struct {
|
||||
Events map[string]Person `json:"events"`
|
||||
}
|
||||
|
||||
type Story struct {
|
||||
Plot Plot `json:"plot"`
|
||||
*Person
|
||||
Location
|
||||
}
|
||||
|
||||
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": {
|
||||
"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]+\\])*)\\}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"country": {
|
||||
"type": "string"
|
||||
},
|
||||
"home": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"country": {
|
||||
"type": "string"
|
||||
},
|
||||
"state": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"country"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"plot": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"events": {
|
||||
"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]+\\])*)\\}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"home": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"country": {
|
||||
"type": "string"
|
||||
},
|
||||
"state": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"country"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"name",
|
||||
"home"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"events"
|
||||
]
|
||||
},
|
||||
"state": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"plot",
|
||||
"name",
|
||||
"home",
|
||||
"country"
|
||||
]
|
||||
}`
|
||||
|
||||
t.Log("[DEBUG] actual: ", string(jsonSchema))
|
||||
t.Log("[DEBUG] expected: ", expected)
|
||||
assert.Equal(t, expected, string(jsonSchema))
|
||||
}
|
||||
|
||||
func TestErrorWithTrace(t *testing.T) {
|
||||
tracker := newTracker()
|
||||
dummyType := reflect.TypeOf(struct{}{})
|
||||
|
|
Loading…
Reference in New Issue