forked from zerodha/gokiteconnect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_test.go
58 lines (50 loc) · 1.28 KB
/
utils_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
52
53
54
55
56
57
58
package kiteapi
import (
"encoding/json"
"testing"
"github.com/gocarina/gocsv"
)
func TestCustomUnmarshalJSON(t *testing.T) {
t.Parallel()
type sampleJSON struct {
Date Time `json:"date"`
}
testCases := []struct {
input string
isZero bool
}{
{"{\"date\":\"2006-01-02\"}", false},
{"{\"date\":\"2006-01-02 15:04:05\"}", false},
{"{\"date\":\"2006-01-02T15:04:05-0700\"}", false},
{"{\"date\":\"2006-01-02T\"}", true},
}
for _, j := range testCases {
res := sampleJSON{}
json.Unmarshal([]byte(j.input), &res)
if res.Date.IsZero() != j.isZero {
t.Errorf("Custom time JSON parsing failed. Expected: %v, Got: %v, Test string: %s", j.isZero, res.Date.IsZero(), j.input)
}
}
}
func TestCustomUnmarshalCSV(t *testing.T) {
t.Parallel()
type sampleCSV struct {
Date Time `csv:"date"`
}
testCases := []struct {
input string
isZero bool
}{
{"date\n2006-01-02", false},
{"date\n2006-01-02 15:04:05", false},
{"date\n2006-01-02T15:04:05-0700", false},
{"date\n2006-01-02:", true},
}
for _, j := range testCases {
res := []sampleCSV{}
gocsv.UnmarshalBytes([]byte(j.input), &res)
if res[0].Date.IsZero() != j.isZero {
t.Errorf("Custom time CSV parsing failed. Expected: %v, Got: %v, Test string: %s", j.isZero, res[0].Date.IsZero(), j.input)
}
}
}