feat(client): add one more test for Client.GetAuthor (#4)
This commit is contained in:
parent
a75bf3a95a
commit
636c363231
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue