2021-01-22 21:47:22 +00:00
|
|
|
// Package groupme defines a client capable of executing API commands for the GroupMe chat service
|
2020-07-30 02:20:57 +00:00
|
|
|
package groupme
|
|
|
|
|
|
|
|
import (
|
2021-01-22 21:47:22 +00:00
|
|
|
"context"
|
2020-07-30 02:20:57 +00:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ClientSuite struct{ APISuite }
|
|
|
|
|
|
|
|
func (s *ClientSuite) SetupSuite() {
|
|
|
|
serverMux := http.NewServeMux()
|
|
|
|
serverMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
_, err := w.Write([]byte("error"))
|
|
|
|
s.Require().NoError(err)
|
|
|
|
})
|
|
|
|
s.handler = serverMux
|
|
|
|
s.setupSuite()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ClientSuite) SetupTest() {
|
|
|
|
s.client = NewClient("")
|
|
|
|
s.Require().NotNil(s.client)
|
|
|
|
|
|
|
|
s.client.endpointBase = s.addr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ClientSuite) TestClient_Close() {
|
|
|
|
s.Assert().NoError(s.client.Close())
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:44:28 +00:00
|
|
|
func (s *ClientSuite) TestClient_do_PostContentType() {
|
|
|
|
req, err := http.NewRequest("POST", "", nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-01-22 21:47:22 +00:00
|
|
|
s.Assert().Error(s.client.do(context.Background(), req, struct{}{}))
|
2020-08-25 02:44:28 +00:00
|
|
|
s.Assert().EqualValues(req.Header.Get("Content-Type"), "application/json")
|
|
|
|
}
|
|
|
|
|
2020-07-30 02:20:57 +00:00
|
|
|
func (s *ClientSuite) TestClient_do_DoError() {
|
|
|
|
req, err := http.NewRequest("", "", nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-01-22 21:47:22 +00:00
|
|
|
s.Assert().Error(s.client.do(context.Background(), req, struct{}{}))
|
2020-07-30 02:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ClientSuite) TestClient_do_UnmarshalError() {
|
|
|
|
req, err := http.NewRequest("GET", s.addr, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-01-22 21:47:22 +00:00
|
|
|
s.Assert().Error(s.client.do(context.Background(), req, struct{}{}))
|
2020-07-30 02:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(ClientSuite))
|
|
|
|
}
|