mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-05 22:32:20 +01:00
vmctl: follow-up after 95d1d38595
(#1718)
Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
parent
f87d43a5e4
commit
93d4ef1239
@ -61,9 +61,8 @@ func toFloat64(v interface{}) (float64, error) {
|
|||||||
case bool:
|
case bool:
|
||||||
if i {
|
if i {
|
||||||
return 1, nil
|
return 1, nil
|
||||||
} else {
|
|
||||||
return 0, nil
|
|
||||||
}
|
}
|
||||||
|
return 0, nil
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("unexpected value type %v", i)
|
return 0, fmt.Errorf("unexpected value type %v", i)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package influx
|
package influx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -58,3 +59,28 @@ func TestSeries_Unmarshal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestToFloat64(t *testing.T) {
|
||||||
|
f := func(in interface{}, want float64) {
|
||||||
|
t.Helper()
|
||||||
|
got, err := toFloat64(in)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected err: %s", err)
|
||||||
|
}
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("got %v; want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f("123.4", 123.4)
|
||||||
|
f(float64(123.4), 123.4)
|
||||||
|
f(float32(12), 12)
|
||||||
|
f(123, 123)
|
||||||
|
f(true, 1)
|
||||||
|
f(false, 0)
|
||||||
|
f(json.Number("123456.789"), 123456.789)
|
||||||
|
|
||||||
|
_, err := toFloat64("text")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected to get err; got nil instead")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user