1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-20 09:56:49 +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
import (
"testing"
"github.com/stretchr/testify/assert"
)
import "testing"
func TestJsonGetInt64WithString(t *testing.T) {
n := JsonGetInt64("test")
assert.Equal(t, int64(0), n)
}
func TestJsonGetInt64WithInt(t *testing.T) {
n := JsonGetInt64(1234)
assert.Equal(t, int64(0), n)
}
func TestJsonGetInt64WithFloat64(t *testing.T) {
n := JsonGetInt64(float64(1234))
assert.Equal(t, int64(1234), n)
func TestJsonGetInt64(t *testing.T) {
tests := []struct {
name string
input interface{}
want int64
}{
{"String", "test", 0 },
{"Int", 1234, 0 },
{"Float", float64(1234), 1234 },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := JsonGetInt64(tt.input); got != tt.want {
t.Errorf("JsonGetInt64() = %v, want %v", got, tt.want)
}
})
}
}