mirror of https://github.com/databricks/cli.git
add test for errWithTrace
This commit is contained in:
parent
42d82ede6e
commit
2945408f0d
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
const MaxHistoryOccurances = 3
|
||||
|
||||
// TODO: should omit empty denote non required fields in the json schema?
|
||||
// TODO: add tests for the error cases, forcefully triggering them
|
||||
// TODO: Add support for refs in case of a cycle
|
||||
// TODO: handle case of self referential pointers in structs
|
||||
|
@ -83,15 +82,14 @@ func javascriptType(golangType reflect.Type) (JavascriptType, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: add a simple test for this
|
||||
func errWithTrace(prefix string, trace *list.List) error {
|
||||
traceString := "root"
|
||||
curr := trace.Front()
|
||||
for curr.Next() != nil {
|
||||
for curr != nil {
|
||||
traceString += " -> " + curr.Value.(string)
|
||||
curr = curr.Next()
|
||||
}
|
||||
return fmt.Errorf("[ERROR] " + prefix + ". traveral trace: " + traceString)
|
||||
return fmt.Errorf("[ERROR] " + prefix + ". traversal trace: " + traceString)
|
||||
}
|
||||
|
||||
// A wrapper over toProperty function with checks for an cycles to avoid being
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -338,6 +339,21 @@ func TestEmbeddedStructSchema(t *testing.T) {
|
|||
assert.Equal(t, expected, string(jsonSchema))
|
||||
}
|
||||
|
||||
func TestErrorWithTrace(t *testing.T) {
|
||||
debugTrace := list.New()
|
||||
err := errWithTrace("with empty trace", debugTrace)
|
||||
assert.ErrorContains(t, err, "[ERROR] with empty trace. traversal trace: root")
|
||||
|
||||
debugTrace.PushBack("resources")
|
||||
err = errWithTrace("with depth = 1", debugTrace)
|
||||
assert.ErrorContains(t, err, "[ERROR] with depth = 1. traversal trace: root -> resources")
|
||||
|
||||
debugTrace.PushBack("pipelines")
|
||||
debugTrace.PushBack("datasets")
|
||||
err = errWithTrace("with depth = 4", debugTrace)
|
||||
assert.ErrorContains(t, err, "[ERROR] with depth = 4. traversal trace: root -> resources -> pipelines -> datasets")
|
||||
}
|
||||
|
||||
// // Only for testing bundle, will be removed
|
||||
// func TestBundleSchema(t *testing.T) {
|
||||
// elem := config.Root{}
|
||||
|
|
Loading…
Reference in New Issue