MCPcopy
hub / github.com/gin-gonic/gin / testFormBindingForTime

Function testFormBindingForTime

binding/binding_test.go:955–980  ·  view source on GitHub ↗
(t *testing.T, method, path, badPath, body, badBody string)

Source from the content-addressed store, hash-verified

953}
954
955func 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
982func testFormBindingForTimeNotUnixFormat(t *testing.T, method, path, badPath, body, badBody string) {
983 b := Form

Callers 2

TestBindingFormForTimeFunction · 0.85
TestBindingFormForTime2Function · 0.85

Calls 5

requestWithBodyFunction · 0.85
NameMethod · 0.65
BindMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected