(t *testing.T, method, path, badPath, body, badBody string)
| 953 | } |
| 954 | |
| 955 | func testFormBindingForTime(t *testing.T, method, path, badPath, body, badBody string) { |
| 956 | b := Form |
| 957 | assert.Equal(t, "form", b.Name()) |
| 958 | |
| 959 | obj := FooBarStructForTimeType{} |
| 960 | req := requestWithBody(method, path, body) |
| 961 | if method == http.MethodPost { |
| 962 | req.Header.Add("Content-Type", MIMEPOSTForm) |
| 963 | } |
| 964 | err := b.Bind(req, &obj) |
| 965 | |
| 966 | require.NoError(t, err) |
| 967 | assert.Equal(t, int64(1510675200), obj.TimeFoo.Unix()) |
| 968 | assert.Equal(t, "Asia/Chongqing", obj.TimeFoo.Location().String()) |
| 969 | assert.Equal(t, int64(-62135596800), obj.TimeBar.Unix()) |
| 970 | assert.Equal(t, "UTC", obj.TimeBar.Location().String()) |
| 971 | assert.Equal(t, int64(1562400033000000123), obj.CreateTime.UnixNano()) |
| 972 | assert.Equal(t, int64(1562400033), obj.UnixTime.Unix()) |
| 973 | assert.Equal(t, int64(1562400033001), obj.UnixMilliTime.UnixMilli()) |
| 974 | assert.Equal(t, int64(1562400033000012), obj.UnixMicroTime.UnixMicro()) |
| 975 | |
| 976 | obj = FooBarStructForTimeType{} |
| 977 | req = requestWithBody(method, badPath, badBody) |
| 978 | err = JSON.Bind(req, &obj) |
| 979 | require.Error(t, err) |
| 980 | } |
| 981 | |
| 982 | func testFormBindingForTimeNotUnixFormat(t *testing.T, method, path, badPath, body, badBody string) { |
| 983 | b := Form |
no test coverage detected