(t *testing.T)
| 2022 | } |
| 2023 | |
| 2024 | func TestValueBinder_Durations(t *testing.T) { |
| 2025 | exampleDuration := 42 * time.Second |
| 2026 | exampleDuration2 := 1 * time.Millisecond |
| 2027 | var testCases = []struct { |
| 2028 | name string |
| 2029 | whenURL string |
| 2030 | expectError string |
| 2031 | givenBindErrors []error |
| 2032 | expectValue []time.Duration |
| 2033 | givenFailFast bool |
| 2034 | whenMust bool |
| 2035 | }{ |
| 2036 | { |
| 2037 | name: "ok, binds value", |
| 2038 | whenURL: "/search?param=42s¶m=1ms", |
| 2039 | expectValue: []time.Duration{exampleDuration, exampleDuration2}, |
| 2040 | }, |
| 2041 | { |
| 2042 | name: "ok, params values empty, value is not changed", |
| 2043 | whenURL: "/search?nope=1", |
| 2044 | expectValue: []time.Duration(nil), |
| 2045 | }, |
| 2046 | { |
| 2047 | name: "nok, previous errors fail fast without binding value", |
| 2048 | givenFailFast: true, |
| 2049 | givenBindErrors: []error{errors.New("previous error")}, |
| 2050 | whenURL: "/search?param=1¶m=100", |
| 2051 | expectValue: []time.Duration(nil), |
| 2052 | expectError: "previous error", |
| 2053 | }, |
| 2054 | { |
| 2055 | name: "ok (must), binds value", |
| 2056 | whenMust: true, |
| 2057 | whenURL: "/search?param=42s¶m=1ms", |
| 2058 | expectValue: []time.Duration{exampleDuration, exampleDuration2}, |
| 2059 | }, |
| 2060 | { |
| 2061 | name: "ok (must), params values empty, returns error, value is not changed", |
| 2062 | whenMust: true, |
| 2063 | whenURL: "/search?nope=1", |
| 2064 | expectValue: []time.Duration(nil), |
| 2065 | expectError: "code=400, message=required field value is empty, field=param", |
| 2066 | }, |
| 2067 | { |
| 2068 | name: "nok (must), previous errors fail fast without binding value", |
| 2069 | givenFailFast: true, |
| 2070 | givenBindErrors: []error{errors.New("previous error")}, |
| 2071 | whenMust: true, |
| 2072 | whenURL: "/search?param=1¶m=100", |
| 2073 | expectValue: []time.Duration(nil), |
| 2074 | expectError: "previous error", |
| 2075 | }, |
| 2076 | } |
| 2077 | |
| 2078 | for _, tc := range testCases { |
| 2079 | t.Run(tc.name, func(t *testing.T) { |
| 2080 | c := createTestContext(tc.whenURL, nil, nil) |
| 2081 | b := QueryParamsBinder(c).FailFast(tc.givenFailFast) |
nothing calls this directly
no test coverage detected
searching dependent graphs…