(t *testing.T)
| 1945 | } |
| 1946 | |
| 1947 | func TestValueBinder_Duration(t *testing.T) { |
| 1948 | example := 42 * time.Second |
| 1949 | var testCases = []struct { |
| 1950 | name string |
| 1951 | whenURL string |
| 1952 | expectError string |
| 1953 | givenBindErrors []error |
| 1954 | expectValue time.Duration |
| 1955 | givenFailFast bool |
| 1956 | whenMust bool |
| 1957 | }{ |
| 1958 | { |
| 1959 | name: "ok, binds value", |
| 1960 | whenURL: "/search?param=42s¶m=1ms", |
| 1961 | expectValue: example, |
| 1962 | }, |
| 1963 | { |
| 1964 | name: "ok, params values empty, value is not changed", |
| 1965 | whenURL: "/search?nope=1", |
| 1966 | expectValue: 0, |
| 1967 | }, |
| 1968 | { |
| 1969 | name: "nok, previous errors fail fast without binding value", |
| 1970 | givenFailFast: true, |
| 1971 | whenURL: "/search?param=1¶m=100", |
| 1972 | expectValue: 0, |
| 1973 | expectError: "previous error", |
| 1974 | }, |
| 1975 | { |
| 1976 | name: "ok (must), binds value", |
| 1977 | whenMust: true, |
| 1978 | whenURL: "/search?param=42s¶m=1ms", |
| 1979 | expectValue: example, |
| 1980 | }, |
| 1981 | { |
| 1982 | name: "ok (must), params values empty, returns error, value is not changed", |
| 1983 | whenMust: true, |
| 1984 | whenURL: "/search?nope=1", |
| 1985 | expectValue: 0, |
| 1986 | expectError: "code=400, message=required field value is empty, field=param", |
| 1987 | }, |
| 1988 | { |
| 1989 | name: "nok (must), previous errors fail fast without binding value", |
| 1990 | givenFailFast: true, |
| 1991 | whenMust: true, |
| 1992 | whenURL: "/search?param=1¶m=100", |
| 1993 | expectValue: 0, |
| 1994 | expectError: "previous error", |
| 1995 | }, |
| 1996 | } |
| 1997 | |
| 1998 | for _, tc := range testCases { |
| 1999 | t.Run(tc.name, func(t *testing.T) { |
| 2000 | c := createTestContext(tc.whenURL, nil, nil) |
| 2001 | b := QueryParamsBinder(c).FailFast(tc.givenFailFast) |
| 2002 | if tc.givenFailFast { |
| 2003 | b.errors = []error{errors.New("previous error")} |
| 2004 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…