Merge pull request #2607 from my-git9/metricstest3
add ut for util/metrics
This commit is contained in:
commit
d46db85ba4
|
@ -19,16 +19,6 @@ func GetResultByError(err error) string {
|
|||
return ResultSuccess
|
||||
}
|
||||
|
||||
// DurationInMicroseconds gets the time in microseconds.
|
||||
func DurationInMicroseconds(start time.Time) float64 {
|
||||
return float64(time.Since(start).Nanoseconds()) / float64(time.Microsecond.Nanoseconds())
|
||||
}
|
||||
|
||||
// DurationInMilliseconds gets the time in milliseconds.
|
||||
func DurationInMilliseconds(start time.Time) float64 {
|
||||
return float64(time.Since(start).Nanoseconds()) / float64(time.Millisecond.Nanoseconds())
|
||||
}
|
||||
|
||||
// DurationInSeconds gets the time in seconds.
|
||||
func DurationInSeconds(start time.Time) float64 {
|
||||
return time.Since(start).Seconds()
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetResultByError(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
error error
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "error is nil",
|
||||
error: nil,
|
||||
want: "success",
|
||||
},
|
||||
{
|
||||
name: "error is not nil",
|
||||
error: errors.New("hello,error"),
|
||||
want: "error",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetResultByError(tt.error); got != tt.want {
|
||||
t.Errorf("GetResultByError() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue