1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-07-04 12:03:43 +02:00

src/utils/json_test.go: refactor test functions into a single one.

This commit is contained in:
Henrik Hautakoski 2022-10-21 13:19:34 +02:00
parent 3568e7c908
commit aa98134a1e
No known key found for this signature in database
GPG key ID: 608414D93E862CCD

View file

@ -1,25 +1,22 @@
package utils package utils
import ( import "testing"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJsonGetInt64WithString(t *testing.T) { func TestJsonGetInt64(t *testing.T) {
tests := []struct {
n := JsonGetInt64("test") name string
assert.Equal(t, int64(0), n) input interface{}
want int64
}{
{"String", "test", 0 },
{"Int", 1234, 0 },
{"Float", float64(1234), 1234 },
} }
for _, tt := range tests {
func TestJsonGetInt64WithInt(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := JsonGetInt64(tt.input); got != tt.want {
n := JsonGetInt64(1234) t.Errorf("JsonGetInt64() = %v, want %v", got, tt.want)
assert.Equal(t, int64(0), n) }
})
} }
func TestJsonGetInt64WithFloat64(t *testing.T) {
n := JsonGetInt64(float64(1234))
assert.Equal(t, int64(1234), n)
} }