Correct context uses
`doAPI`'s `context` does not work due to `WithContext` immutability. `Authenticate` and `RegisterApp` does not use `context` although they needs `context`, so their `context` does not work also. This commit fixes them and add test cases.
This commit is contained in:
parent
909a57c5ea
commit
fb53d41dd9
5 changed files with 100 additions and 2 deletions
23
apps_test.go
23
apps_test.go
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRegisterApp(t *testing.T) {
|
||||
|
@ -41,3 +42,25 @@ func TestRegisterApp(t *testing.T) {
|
|||
t.Fatalf("want %q but %q", "bar", app.ClientSecret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterAppWithCancel(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(3 * time.Second)
|
||||
fmt.Fprintln(w, `{"client_id": "foo", "client_secret": "bar"}`)
|
||||
return
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go cancel()
|
||||
_, err := RegisterApp(ctx, &AppConfig{
|
||||
Server: ts.URL,
|
||||
Scopes: "read write follow",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
if want := "Post " + ts.URL + "/api/v1/apps: context canceled"; want != err.Error() {
|
||||
t.Fatalf("want %q but %q", want, err.Error())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue