feat(client): add one more test for Client.GetAuthor (#4)

This commit is contained in:
Dawid Wysokiński 2022-05-31 17:16:36 +02:00 committed by GitHub
parent a75bf3a95a
commit 636c363231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -27,8 +27,12 @@ func TestClient_GetAuthor(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != fmt.Sprintf("/autor/%s/x", author.ID) || r.Method != http.MethodGet {
w.WriteHeader(http.StatusBadRequest)
if r.URL.Path != fmt.Sprintf("/autor/%s/x", author.ID) {
w.WriteHeader(http.StatusNotFound)
return
}
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
@ -45,4 +49,19 @@ func TestClient_GetAuthor(t *testing.T) {
})
}
})
t.Run("ERR: author not found", func(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
defer srv.Close()
result, err := lubimyczytac.
NewClient(srv.Client(), lubimyczytac.WithBaseURL(srv.URL)).
GetAuthor(context.Background(), "123")
assert.ErrorIs(t, err, lubimyczytac.ErrAuthorNotFound)
assert.Zero(t, result)
})
}

View File

@ -18,12 +18,12 @@ import (
)
const (
defaultClientTimeout = 5 * time.Second
clientTimeout = 5 * time.Second
)
func main() {
httpSrv := newServer(newRouter(lubimyczytac.NewClient(&http.Client{
Timeout: defaultClientTimeout,
Timeout: clientTimeout,
})))
go func(httpSrv *http.Server) {