databricks-cli/libs/dyn/dynvar/lookup_test.go

28 lines
606 B
Go

package dynvar_test
import (
"testing"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/dyn/dynvar"
"github.com/stretchr/testify/assert"
)
func TestDefaultLookup(t *testing.T) {
lookup := dynvar.DefaultLookup(dyn.V(map[string]dyn.Value{
"a": dyn.V("a"),
"b": dyn.V("b"),
}))
v1, err := lookup(dyn.NewPath(dyn.Key("a")))
assert.NoError(t, err)
assert.Equal(t, dyn.V("a"), v1)
v2, err := lookup(dyn.NewPath(dyn.Key("b")))
assert.NoError(t, err)
assert.Equal(t, dyn.V("b"), v2)
_, err = lookup(dyn.NewPath(dyn.Key("c")))
assert.True(t, dyn.IsNoSuchKeyError(err))
}