-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98d1595
commit 75cb3ea
Showing
3 changed files
with
129 additions
and
21 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
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,66 @@ | ||
package debugserver | ||
|
||
import "testing" | ||
|
||
func TestRequestID(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input string | ||
expected string | ||
expectedError error | ||
}{ | ||
{ | ||
name: "valid case", | ||
input: "/buckets/test/", | ||
expected: "test", | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "valid case", | ||
input: "/buckets/_/", | ||
expected: "_", | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "valid case without trailing slash", | ||
input: "/buckets/test", | ||
expected: "test", | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "valid case, with multiple levels", | ||
input: "/buckets/test1/test2", | ||
expected: "test1", | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "invalid case with no ID and double slashes", | ||
input: "/buckets//", | ||
expected: "", | ||
expectedError: errNoID, | ||
}, | ||
{ | ||
name: "invalid case with no ID", | ||
input: "/buckets", | ||
expected: "", | ||
expectedError: errNoID, | ||
}, | ||
{ | ||
name: "invalid case with blank ID", | ||
input: "/buckets/ /", | ||
expected: "", | ||
expectedError: errNoID, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
actual, err := requestID(c.input) | ||
if err != c.expectedError { | ||
t.Errorf("Got error: %v, expected: %v, id: %q, case: %q", err, c.expectedError, actual, c.name) | ||
} | ||
|
||
if actual != c.expected { | ||
t.Errorf("Got %q, expected: %q, case: %q", actual, c.expected, c.name) | ||
} | ||
} | ||
} |