forked from databricks/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle normalization of
dyn.KindTime
into an any type (databricks#1836
) ## Changes The issue reported in databricks#1828 illustrates how using a YAML timestamp-like value (a date in this case) causes an issue during conversion to and from the typed configuration tree. We use the `AsAny()` function on the `dyn.Value` when normalizing for the `any` type. We only use the `any` type for variable values, because they can assume every type. The `AsAny()` function returns a `time.Time` for the time value during conversion **to** the typed configuration tree. Upon conversion **from** the typed configuration tree back into the dynamic configuration tree, we cannot distinguish a `time.Time` struct from any other struct. To address this, we use the underlying string value of the time value when we normalize for the `any` type. Fixes databricks#1828. ## Tests Existing unit tests pass
- Loading branch information
Showing
4 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
bundle: | ||
name: issue_1828 | ||
|
||
variables: | ||
# One entry for each of the underlying YAML (or [dyn.Kind]) types. | ||
# The test confirms we can convert to and from the typed configuration without losing information. | ||
|
||
map: | ||
default: | ||
foo: bar | ||
|
||
sequence: | ||
default: | ||
- foo | ||
- bar | ||
|
||
string: | ||
default: foo | ||
|
||
bool: | ||
default: true | ||
|
||
int: | ||
default: 42 | ||
|
||
float: | ||
default: 3.14 | ||
|
||
time: | ||
default: 2021-01-01 | ||
|
||
nil: | ||
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package config_tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIssue1828(t *testing.T) { | ||
b := load(t, "./issue_1828") | ||
|
||
if assert.Contains(t, b.Config.Variables, "map") { | ||
assert.Equal(t, map[string]any{ | ||
"foo": "bar", | ||
}, b.Config.Variables["map"].Default) | ||
} | ||
|
||
if assert.Contains(t, b.Config.Variables, "sequence") { | ||
assert.Equal(t, []any{ | ||
"foo", | ||
"bar", | ||
}, b.Config.Variables["sequence"].Default) | ||
} | ||
|
||
if assert.Contains(t, b.Config.Variables, "string") { | ||
assert.Equal(t, "foo", b.Config.Variables["string"].Default) | ||
} | ||
|
||
if assert.Contains(t, b.Config.Variables, "bool") { | ||
assert.Equal(t, true, b.Config.Variables["bool"].Default) | ||
} | ||
|
||
if assert.Contains(t, b.Config.Variables, "int") { | ||
assert.Equal(t, 42, b.Config.Variables["int"].Default) | ||
} | ||
|
||
if assert.Contains(t, b.Config.Variables, "float") { | ||
assert.Equal(t, 3.14, b.Config.Variables["float"].Default) | ||
} | ||
|
||
if assert.Contains(t, b.Config.Variables, "time") { | ||
assert.Equal(t, "2021-01-01", b.Config.Variables["time"].Default) | ||
} | ||
|
||
if assert.Contains(t, b.Config.Variables, "nil") { | ||
assert.Equal(t, nil, b.Config.Variables["nil"].Default) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters