-
Notifications
You must be signed in to change notification settings - Fork 145
/
rfc2822_test.go
49 lines (43 loc) · 1.08 KB
/
rfc2822_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
package mailgun
import (
"encoding/json"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestUnmarshalRFC2822Time(t *testing.T) {
type Req struct {
CreatedAt RFC2822Time `json:"created_at"`
}
tests := []struct {
name string
s string
want Req
wantErr bool
}{
{
name: "RFC1123",
s: `{"created_at":"Thu, 13 Oct 2011 18:02:00 GMT"}`,
wantErr: false,
want: Req{CreatedAt: RFC2822Time(time.Date(2011, 10, 13, 18, 2, 0, 0, time.UTC))},
},
{
name: "RFC1123Z",
s: `{"created_at":"Thu, 13 Oct 2011 18:02:00 +0000"}`,
wantErr: false,
want: Req{CreatedAt: RFC2822Time(time.Date(2011, 10, 13, 18, 2, 0, 0, time.UTC))},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var req Req
err := json.Unmarshal([]byte(tt.s), &req)
if (err != nil) != tt.wantErr {
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
}
require.True(t, time.Time(tt.want.CreatedAt).Equal(time.Time(req.CreatedAt)),
fmt.Sprintf("want: %s; got: %s", tt.want.CreatedAt, req.CreatedAt))
})
}
}