-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from hound-search/AlexTalks/tests
Add support for manually setting a limit on results(copy)
- Loading branch information
Showing
9 changed files
with
1,556 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var parseAsIntAndUintTests = map[string]struct { | ||
numResults string | ||
min int | ||
max int | ||
def int | ||
expected int | ||
} { | ||
"parse error test case": {"not a parsable integer", 101, 1000, 5000, 5000}, | ||
"less than min test case": {"100", 101, 1000, 5000, 101}, | ||
"greater than max test case": {"1001", 101, 1000, 5000, 1000}, | ||
"within limits test case": {"100", 0, 100, 5000, 100}, | ||
} | ||
|
||
func TestParseAsIntAndUint(t *testing.T) { | ||
for name, td := range parseAsIntAndUintTests { | ||
t.Run(name, func(t *testing.T) { | ||
if got, expected := | ||
parseAsUintValue(td.numResults, uint(td.min), uint(td.max), uint(td.def)), uint(td.expected); got != expected { | ||
t.Fatalf("parseAsUintValue - %s: returned %d; expected %d", name, got, expected) | ||
} | ||
|
||
if got, expected := | ||
parseAsIntValue(td.numResults, td.min, td.max, td.def), td.expected; got != expected { | ||
t.Fatalf("parseAsIntValue - %s: returned %d; expected %d", name, got, expected) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.