mirror of https://github.com/databricks/cli.git
added test for pointers in structs
This commit is contained in:
parent
4dfe3cea9a
commit
1a8627fc26
|
@ -12,7 +12,6 @@ import (
|
|||
// TODO: Add example documentation
|
||||
// TODO: Do final checks for more validation that can be added to json schema
|
||||
// TODO: Run all tests to see code coverage and add tests for missing assertions
|
||||
// TODO: test all permutations of types [primitives, maps, arrays, objects]
|
||||
|
||||
// defines schema for a json object
|
||||
type Schema struct {
|
||||
|
@ -100,7 +99,6 @@ const (
|
|||
)
|
||||
|
||||
// TODO: document that only string keys allowed in maps
|
||||
// TODO: document mapping between schema and json
|
||||
func javascriptType(golangType reflect.Type) (JavascriptType, error) {
|
||||
switch golangType.Kind() {
|
||||
case reflect.Bool:
|
||||
|
@ -183,7 +181,6 @@ func addStructFields(fields []reflect.StructField, golangType reflect.Type) []re
|
|||
continue
|
||||
}
|
||||
|
||||
// TODO: add test case for pointer too
|
||||
fieldType := field.Type
|
||||
if fieldType.Kind() == reflect.Pointer {
|
||||
fieldType = fieldType.Elem()
|
||||
|
|
|
@ -684,6 +684,69 @@ func TestDashFieldsAreSkipped(t *testing.T) {
|
|||
assert.Equal(t, expectedSchema, string(jsonSchema))
|
||||
}
|
||||
|
||||
func TestPointerInStructSchema(t *testing.T) {
|
||||
|
||||
type Bar struct {
|
||||
PtrVal2 *int `json:"ptr_val2"`
|
||||
}
|
||||
|
||||
type Foo struct {
|
||||
PtrInt *int `json:"ptr_int"`
|
||||
PtrString *string `json:"ptr_string"`
|
||||
FloatVal float32 `json:"float_val"`
|
||||
PtrBar *Bar `json:"ptr_bar"`
|
||||
Bar *Bar `json:"bar"`
|
||||
}
|
||||
|
||||
elem := Foo{}
|
||||
|
||||
schema, err := NewSchema(reflect.TypeOf(elem))
|
||||
require.NoError(t, err)
|
||||
|
||||
jsonSchema, err := json.MarshalIndent(schema, " ", " ")
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedSchema :=
|
||||
`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bar": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ptr_val2": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"float_val": {
|
||||
"type": "number"
|
||||
},
|
||||
"ptr_bar": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ptr_val2": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"ptr_int": {
|
||||
"type": "number"
|
||||
},
|
||||
"ptr_string": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}`
|
||||
|
||||
t.Log("[DEBUG] actual: ", string(jsonSchema))
|
||||
t.Log("[DEBUG] expected: ", expectedSchema)
|
||||
|
||||
assert.Equal(t, expectedSchema, string(jsonSchema))
|
||||
}
|
||||
|
||||
// TODO: last test to do once all the todos are done
|
||||
func TestObjectSchema(t *testing.T) {
|
||||
type Person struct {
|
||||
|
|
Loading…
Reference in New Issue