forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_test.go
51 lines (44 loc) · 906 Bytes
/
socket_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package server
import (
"math"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEncode(t *testing.T) {
now := time.Now()
tc := []struct {
in interface{}
out string
}{
{int64(1), "1"},
{math.NaN(), "null"},
{float64(1.23456), "1.2346"},
{"1.2345", "\"1.2345\""},
{time.Hour, "3600"},
{"minpv", "\"minpv\""},
{time.Time{}, "null"},
{now, "\"" + now.Format(time.RFC3339) + "\""},
}
for _, tc := range tc {
out, err := encode(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.out, out)
}
}
func TestEncodeSlice(t *testing.T) {
tc := []struct {
in interface{}
out string
}{
{[]string{"a", "b"}, `["a","b"]`},
{[2]int64{1, 2}, `[1,2]`},
{[]float64{1, math.NaN()}, `[1,null]`},
}
for _, tc := range tc {
out, err := encodeSlice(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.out, out)
}
}