-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
1b5a923
commit 1103c32
Showing
1 changed file
with
34 additions
and
0 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
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) | ||
} | ||
}) | ||
} | ||
} |