Initial release of bdrclone
This commit is contained in:
25
internal/auth/auth_test.go
Normal file
25
internal/auth/auth_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user