From aa98134a1eb81f40853a9e78ce9361cf04a01153 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 21 Oct 2022 13:19:34 +0200 Subject: [PATCH] src/utils/json_test.go: refactor test functions into a single one. --- src/utils/json_test.go | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/utils/json_test.go b/src/utils/json_test.go index 81a9b3d..69f380f 100644 --- a/src/utils/json_test.go +++ b/src/utils/json_test.go @@ -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) + } + }) + } }