vmctl: follow-up after 95d1d38595 (#1718)

Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2021-10-18 15:10:44 +03:00 committed by Aliaksandr Valialkin
parent f87d43a5e4
commit 93d4ef1239
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 27 additions and 2 deletions

View File

@ -61,9 +61,8 @@ func toFloat64(v interface{}) (float64, error) {
case bool:
if i {
return 1, nil
} else {
return 0, nil
}
return 0, nil
default:
return 0, fmt.Errorf("unexpected value type %v", i)
}

View File

@ -1,6 +1,7 @@
package influx
import (
"encoding/json"
"reflect"
"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")
}
}