26 lines
713 B
Go
26 lines
713 B
Go
package auth
|
|
|
|
import "testing"
|
|
|
|
func TestParseAuthorizationCode(t *testing.T) {
|
|
tests := map[string]string{
|
|
"plain-code\n": "plain-code",
|
|
"http://openapi.baidu.com/success?code=a%2Bb": "a+b",
|
|
"https://example.test/?state=x&code=xyz": "xyz",
|
|
}
|
|
for input, want := range tests {
|
|
got, err := parseAuthorizationCode(input)
|
|
if err != nil {
|
|
t.Fatalf("parseAuthorizationCode(%q): %v", input, err)
|
|
}
|
|
if got != want {
|
|
t.Errorf("parseAuthorizationCode(%q) = %q, want %q", input, got, want)
|
|
}
|
|
}
|
|
for _, input := range []string{"", " \n", "two words"} {
|
|
if _, err := parseAuthorizationCode(input); err == nil {
|
|
t.Errorf("parseAuthorizationCode(%q) unexpectedly succeeded", input)
|
|
}
|
|
}
|
|
}
|