diff --git a/libs/dyn/convert/to_typed.go b/libs/dyn/convert/to_typed.go index 534a1eeff..7fceedd54 100644 --- a/libs/dyn/convert/to_typed.go +++ b/libs/dyn/convert/to_typed.go @@ -248,7 +248,7 @@ func toTypedInt(dst reflect.Value, src dyn.Value) error { return nil case dyn.KindFloat: v := src.MustFloat() - if canConvertToInt(v) { + if v == float64(int64(v)) { dst.SetInt(int64(src.MustFloat())) return nil } @@ -275,10 +275,6 @@ func toTypedInt(dst reflect.Value, src dyn.Value) error { } } -func canConvertToInt(v float64) bool { - return v == float64(int64(v)) -} - func toTypedFloat(dst reflect.Value, src dyn.Value) error { switch src.Kind() { case dyn.KindFloat: diff --git a/libs/dyn/jsonloader/json_test.go b/libs/dyn/jsonloader/json_test.go index fdcf9dda7..24299f207 100644 --- a/libs/dyn/jsonloader/json_test.go +++ b/libs/dyn/jsonloader/json_test.go @@ -5,7 +5,7 @@ import ( "github.com/databricks/cli/libs/dyn/convert" "github.com/databricks/databricks-sdk-go/service/jobs" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) const jsonData = ` @@ -45,11 +45,11 @@ const jsonData = ` func TestJsonLoader(t *testing.T) { v, err := LoadJSON([]byte(jsonData), "(inline)") - require.NoError(t, err) + assert.NoError(t, err) var r jobs.ResetJob err = convert.ToTyped(&r, v) - require.NoError(t, err) + assert.NoError(t, err) } const malformedMap = ` @@ -64,7 +64,7 @@ const malformedMap = ` func TestJsonLoaderMalformedMap(t *testing.T) { _, err := LoadJSON([]byte(malformedMap), "(inline)") - require.ErrorContains(t, err, "error decoding JSON at (inline):6:16: invalid character ',' after object key") + assert.ErrorContains(t, err, "error decoding JSON at (inline):6:16: invalid character ',' after object key") } const malformedArray = ` @@ -78,7 +78,7 @@ const malformedArray = ` func TestJsonLoaderMalformedArray(t *testing.T) { _, err := LoadJSON([]byte(malformedArray), "path/to/file.json") - require.ErrorContains(t, err, "error decoding JSON at path/to/file.json:6:28: invalid character ']' looking for beginning of value") + assert.ErrorContains(t, err, "error decoding JSON at path/to/file.json:6:28: invalid character ']' looking for beginning of value") } const eofData = ` @@ -89,5 +89,5 @@ const eofData = ` func TestJsonLoaderEOF(t *testing.T) { _, err := LoadJSON([]byte(eofData), "path/to/file.json") - require.ErrorContains(t, err, "unexpected end of JSON input") + assert.ErrorContains(t, err, "unexpected end of JSON input") } diff --git a/libs/flags/json_flag.go b/libs/flags/json_flag.go index 3145f82cc..8663916b5 100644 --- a/libs/flags/json_flag.go +++ b/libs/flags/json_flag.go @@ -52,7 +52,7 @@ func (j *JsonFlag) Unmarshal(v any) diag.Diagnostics { // It will convert all the values to the correct types. // For example string literals for booleans and integers will be converted to the correct types. nv, diags := convert.Normalize(v, dv) - if len(diags) > 0 { + if diags.HasError() { return diags }