(t *testing.T)
| 1374 | } |
| 1375 | |
| 1376 | func TestGetRestrictedIntQuery(t *testing.T) { |
| 1377 | |
| 1378 | defaultValue := uint64(42) |
| 1379 | minValue := uint64(20) |
| 1380 | maxValue := uint64(100) |
| 1381 | |
| 1382 | // make sure it returns default value when passed empty Values |
| 1383 | values := make(url.Values) |
| 1384 | restricted := GetRestrictedIntQuery( |
| 1385 | values, |
| 1386 | "foo", |
| 1387 | defaultValue, |
| 1388 | minValue, |
| 1389 | maxValue, |
| 1390 | false, |
| 1391 | ) |
| 1392 | assert.Equal(t, defaultValue, restricted) |
| 1393 | |
| 1394 | // make sure it returns default value when passed Values that doesn't contain key |
| 1395 | values.Set("bar", "99") |
| 1396 | restricted = GetRestrictedIntQuery( |
| 1397 | values, |
| 1398 | "foo", |
| 1399 | defaultValue, |
| 1400 | minValue, |
| 1401 | maxValue, |
| 1402 | false, |
| 1403 | ) |
| 1404 | assert.Equal(t, defaultValue, restricted) |
| 1405 | |
| 1406 | // make sure it returns appropriate value from Values |
| 1407 | values.Set("foo", "99") |
| 1408 | restricted = GetRestrictedIntQuery( |
| 1409 | values, |
| 1410 | "foo", |
| 1411 | defaultValue, |
| 1412 | minValue, |
| 1413 | maxValue, |
| 1414 | false, |
| 1415 | ) |
| 1416 | assert.Equal(t, uint64(99), restricted) |
| 1417 | |
| 1418 | // make sure it is limited to max when value value is over max |
| 1419 | values.Set("foo", "200") |
| 1420 | restricted = GetRestrictedIntQuery( |
| 1421 | values, |
| 1422 | "foo", |
| 1423 | defaultValue, |
| 1424 | minValue, |
| 1425 | maxValue, |
| 1426 | false, |
| 1427 | ) |
| 1428 | assert.Equal(t, maxValue, restricted) |
| 1429 | |
| 1430 | // make sure it is limited to min when value value is under min |
| 1431 | values.Set("foo", "1") |
| 1432 | restricted = GetRestrictedIntQuery( |
| 1433 | values, |
nothing calls this directly
no test coverage detected