MCPcopy Index your code
hub / github.com/labstack/echo / TestValueBinder_BindUnmarshaler

Function TestValueBinder_BindUnmarshaler

binder_test.go:2102–2191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2100}
2101
2102func TestValueBinder_BindUnmarshaler(t *testing.T) {
2103 exampleTime, _ := time.Parse(time.RFC3339, "2020-12-23T09:45:31+02:00")
2104
2105 var testCases = []struct {
2106 expectValue Timestamp
2107 name string
2108 whenURL string
2109 expectError string
2110 givenBindErrors []error
2111 givenFailFast bool
2112 whenMust bool
2113 }{
2114 {
2115 name: "ok, binds value",
2116 whenURL: "/search?param=2020-12-23T09:45:31%2B02:00&param=2000-01-02T09:45:31%2B00:00",
2117 expectValue: Timestamp(exampleTime),
2118 },
2119 {
2120 name: "ok, params values empty, value is not changed",
2121 whenURL: "/search?nope=1",
2122 expectValue: Timestamp{},
2123 },
2124 {
2125 name: "nok, previous errors fail fast without binding value",
2126 givenFailFast: true,
2127 whenURL: "/search?param=1&param=100",
2128 expectValue: Timestamp{},
2129 expectError: "previous error",
2130 },
2131 {
2132 name: "nok, conversion fails, value is not changed",
2133 whenURL: "/search?param=nope&param=100",
2134 expectValue: Timestamp{},
2135 expectError: "code=400, message=failed to bind field value to BindUnmarshaler interface, err=parsing time \"nope\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"nope\" as \"2006\", field=param",
2136 },
2137 {
2138 name: "ok (must), binds value",
2139 whenMust: true,
2140 whenURL: "/search?param=2020-12-23T09:45:31%2B02:00&param=2000-01-02T09:45:31%2B00:00",
2141 expectValue: Timestamp(exampleTime),
2142 },
2143 {
2144 name: "ok (must), params values empty, returns error, value is not changed",
2145 whenMust: true,
2146 whenURL: "/search?nope=1",
2147 expectValue: Timestamp{},
2148 expectError: "code=400, message=required field value is empty, field=param",
2149 },
2150 {
2151 name: "nok (must), previous errors fail fast without binding value",
2152 givenFailFast: true,
2153 whenMust: true,
2154 whenURL: "/search?param=1&param=100",
2155 expectValue: Timestamp{},
2156 expectError: "previous error",
2157 },
2158 {
2159 name: "nok (must), conversion fails, value is not changed",

Callers

nothing calls this directly

Calls 7

TimestampTypeAlias · 0.85
createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorMethod · 0.80
MustBindUnmarshalerMethod · 0.80
BindUnmarshalerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…