Skip to content

Commit ad301f3

Browse files
author
Tsotne Tabidze
committed
Add unit test for UnmarshalJSON
Signed-off-by: Tsotne Tabidze <tsotne@tecton.ai>
1 parent ee1148d commit ad301f3

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package server
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestUnmarshalJSON(t *testing.T) {
9+
u := repeatedValue{}
10+
assert.Nil(t, u.UnmarshalJSON([]byte("[1, 2, 3]")))
11+
assert.Equal(t, []int64{1, 2, 3}, u.int64Val)
12+
13+
u = repeatedValue{}
14+
assert.Nil(t, u.UnmarshalJSON([]byte("[1.2, 2.3, 3.4]")))
15+
assert.Equal(t, []float64{1.2, 2.3, 3.4}, u.doubleVal)
16+
17+
u = repeatedValue{}
18+
assert.Nil(t, u.UnmarshalJSON([]byte("[\"foo\", \"bar\"]")))
19+
assert.Equal(t, []string{"foo", "bar"}, u.stringVal)
20+
21+
u = repeatedValue{}
22+
assert.Nil(t, u.UnmarshalJSON([]byte("[true, false, true]")))
23+
assert.Equal(t, []bool{true, false, true}, u.boolVal)
24+
25+
u = repeatedValue{}
26+
assert.Nil(t, u.UnmarshalJSON([]byte("[[1, 2, 3], [4, 5, 6]]")))
27+
assert.Equal(t, [][]int64{{1, 2, 3}, {4, 5, 6}}, u.int64ListVal)
28+
29+
u = repeatedValue{}
30+
assert.Nil(t, u.UnmarshalJSON([]byte("[[1.2, 2.3, 3.4], [10.2, 20.3, 30.4]]")))
31+
assert.Equal(t, [][]float64{{1.2, 2.3, 3.4}, {10.2, 20.3, 30.4}}, u.doubleListVal)
32+
33+
u = repeatedValue{}
34+
assert.Nil(t, u.UnmarshalJSON([]byte("[[\"foo\", \"bar\"], [\"foo2\", \"bar2\"]]")))
35+
assert.Equal(t, [][]string{{"foo", "bar"}, {"foo2", "bar2"}}, u.stringListVal)
36+
37+
u = repeatedValue{}
38+
assert.Nil(t, u.UnmarshalJSON([]byte("[[true, false, true], [false, true, false]]")))
39+
assert.Equal(t, [][]bool{{true, false, true}, {false, true, false}}, u.boolListVal)
40+
}

0 commit comments

Comments
 (0)