Merge pull request #37 from 178inaba/apps_test
Add fail test cover to TestRegisterApp
This commit is contained in:
commit
7a4a84f70f
37
apps_test.go
37
apps_test.go
|
@ -10,24 +10,53 @@ import (
|
|||
)
|
||||
|
||||
func TestRegisterApp(t *testing.T) {
|
||||
isNotJSON := true
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if r.URL.Path != "/api/v1/apps" {
|
||||
} else if r.URL.Path != "/api/v1/apps" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if r.FormValue("redirect_uris") != "urn:ietf:wg:oauth:2.0:oob" {
|
||||
} else if r.FormValue("redirect_uris") != "urn:ietf:wg:oauth:2.0:oob" {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
} else if isNotJSON {
|
||||
isNotJSON = false
|
||||
fmt.Fprintln(w, `<html><head><title>Apps</title></head></html>`)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `{"client_id": "foo", "client_secret": "bar"}`)
|
||||
return
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
// Status not ok.
|
||||
_, err := RegisterApp(context.Background(), &AppConfig{
|
||||
Server: ts.URL,
|
||||
RedirectURIs: "/",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
|
||||
// Error in url.Parse
|
||||
_, err = RegisterApp(context.Background(), &AppConfig{
|
||||
Server: ":",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
|
||||
// Error in json.NewDecoder
|
||||
_, err = RegisterApp(context.Background(), &AppConfig{
|
||||
Server: ts.URL,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
|
||||
// Success.
|
||||
app, err := RegisterApp(context.Background(), &AppConfig{
|
||||
Server: ts.URL,
|
||||
Scopes: "read write follow",
|
||||
|
|
Loading…
Reference in New Issue
Block a user