github.com/blend/go-sdk@v1.20220411.3/statsd/metric_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package statsd 9 10 import ( 11 "testing" 12 "time" 13 14 "github.com/blend/go-sdk/assert" 15 ) 16 17 func Test_Metric_Float64(t *testing.T) { 18 assert := assert.New(t) 19 20 good := Metric{Value: "3.14"} 21 goodValue, err := good.Float64() 22 assert.Nil(err) 23 assert.Equal(3.14, goodValue) 24 25 bad := Metric{Value: "foo"} 26 badValue, err := bad.Float64() 27 assert.NotNil(err) 28 assert.Zero(badValue) 29 } 30 31 func Test_Metric_Int64(t *testing.T) { 32 assert := assert.New(t) 33 34 good := Metric{Value: "314"} 35 goodValue, err := good.Int64() 36 assert.Nil(err) 37 assert.Equal(314, goodValue) 38 39 bad := Metric{Value: "foo"} 40 badValue, err := bad.Int64() 41 assert.NotNil(err) 42 assert.Zero(badValue) 43 } 44 45 func Test_Metric_Duration(t *testing.T) { 46 assert := assert.New(t) 47 48 good := Metric{Value: "512.12"} 49 goodValue, err := good.Duration() 50 assert.Nil(err) 51 assert.Equal(time.Duration(512.12*float64(time.Millisecond)), goodValue) 52 53 bad := Metric{Value: "foo"} 54 badValue, err := bad.Duration() 55 assert.NotNil(err) 56 assert.Zero(badValue) 57 }