mirror of https://github.com/databricks/cli.git
fixes
This commit is contained in:
parent
75948368a3
commit
cf2ab73903
|
@ -248,7 +248,7 @@ func toTypedInt(dst reflect.Value, src dyn.Value) error {
|
||||||
return nil
|
return nil
|
||||||
case dyn.KindFloat:
|
case dyn.KindFloat:
|
||||||
v := src.MustFloat()
|
v := src.MustFloat()
|
||||||
if canConvertToInt(v) {
|
if v == float64(int64(v)) {
|
||||||
dst.SetInt(int64(src.MustFloat()))
|
dst.SetInt(int64(src.MustFloat()))
|
||||||
return nil
|
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 {
|
func toTypedFloat(dst reflect.Value, src dyn.Value) error {
|
||||||
switch src.Kind() {
|
switch src.Kind() {
|
||||||
case dyn.KindFloat:
|
case dyn.KindFloat:
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/dyn/convert"
|
"github.com/databricks/cli/libs/dyn/convert"
|
||||||
"github.com/databricks/databricks-sdk-go/service/jobs"
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const jsonData = `
|
const jsonData = `
|
||||||
|
@ -45,11 +45,11 @@ const jsonData = `
|
||||||
|
|
||||||
func TestJsonLoader(t *testing.T) {
|
func TestJsonLoader(t *testing.T) {
|
||||||
v, err := LoadJSON([]byte(jsonData), "(inline)")
|
v, err := LoadJSON([]byte(jsonData), "(inline)")
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var r jobs.ResetJob
|
var r jobs.ResetJob
|
||||||
err = convert.ToTyped(&r, v)
|
err = convert.ToTyped(&r, v)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const malformedMap = `
|
const malformedMap = `
|
||||||
|
@ -64,7 +64,7 @@ const malformedMap = `
|
||||||
|
|
||||||
func TestJsonLoaderMalformedMap(t *testing.T) {
|
func TestJsonLoaderMalformedMap(t *testing.T) {
|
||||||
_, err := LoadJSON([]byte(malformedMap), "(inline)")
|
_, 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 = `
|
const malformedArray = `
|
||||||
|
@ -78,7 +78,7 @@ const malformedArray = `
|
||||||
|
|
||||||
func TestJsonLoaderMalformedArray(t *testing.T) {
|
func TestJsonLoaderMalformedArray(t *testing.T) {
|
||||||
_, err := LoadJSON([]byte(malformedArray), "path/to/file.json")
|
_, 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 = `
|
const eofData = `
|
||||||
|
@ -89,5 +89,5 @@ const eofData = `
|
||||||
|
|
||||||
func TestJsonLoaderEOF(t *testing.T) {
|
func TestJsonLoaderEOF(t *testing.T) {
|
||||||
_, err := LoadJSON([]byte(eofData), "path/to/file.json")
|
_, 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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (j *JsonFlag) Unmarshal(v any) diag.Diagnostics {
|
||||||
// It will convert all the values to the correct types.
|
// 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.
|
// For example string literals for booleans and integers will be converted to the correct types.
|
||||||
nv, diags := convert.Normalize(v, dv)
|
nv, diags := convert.Normalize(v, dv)
|
||||||
if len(diags) > 0 {
|
if diags.HasError() {
|
||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue