Skip to content

Commit

Permalink
Merge pull request #9 from omc/chore/update-test-handlefuncs
Browse files Browse the repository at this point in the history
Chore/update test handlefuncs
  • Loading branch information
momer authored May 3, 2024
2 parents 7372fc0 + 81908a0 commit 96850a6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
7 changes: 4 additions & 3 deletions bonsai/client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http/httptest"
"testing"

"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"golang.org/x/time/rate"
Expand All @@ -25,7 +26,7 @@ type ClientImplTestSuite struct {
suite.Suite

// serveMux is the request multiplexer used for tests
serveMux *http.ServeMux
serveMux *chi.Mux
// server is the testing server on some local port
server *httptest.Server
// client allows each test to have a reachable *Client for testing
Expand All @@ -34,7 +35,7 @@ type ClientImplTestSuite struct {

func (s *ClientImplTestSuite) SetupSuite() {
// Configure http client and other miscellany
s.serveMux = http.NewServeMux()
s.serveMux = chi.NewRouter()
s.server = httptest.NewServer(s.serveMux)
token, err := NewToken("TestToken")
if err != nil {
Expand Down Expand Up @@ -90,7 +91,7 @@ func (s *ClientImplTestSuite) TestClientAll() {
expectedPage = 1
)

s.serveMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
s.serveMux.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set(HTTPHeaderContentType, HTTPContentTypeJSON)

respBody, _ := NewResponse()
Expand Down
7 changes: 2 additions & 5 deletions bonsai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *ClientTestSuite) TestClientResponseError() {
const p = "/clusters/doesnotexist-1234"

// Configure Servemux to serve the error response at this path
s.serveMux.HandleFunc(p, func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get(p, func(w http.ResponseWriter, _ *http.Request) {
var err error

w.Header().Set("Content-Type", bonsai.HTTPContentTypeJSON)
Expand All @@ -125,11 +125,8 @@ func (s *ClientTestSuite) TestClientResponseError() {
}

func (s *ClientTestSuite) TestClientResponseWithPagination() {
s.serveMux.HandleFunc("/clusters", func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get("/clusters", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("RateLimit-Limit", "1000")
w.Header().Set("RateLimit-Remaining", "999")
w.Header().Set("RateLimit-Reset", "1511954577")
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, `
{
Expand Down
4 changes: 2 additions & 2 deletions bonsai/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (s *ClientTestSuite) TestPlanClient_All() {
s.serveMux.HandleFunc(bonsai.PlanAPIBasePath, func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get(bonsai.PlanAPIBasePath, func(w http.ResponseWriter, _ *http.Request) {
respStr := `
{
"plans": [
Expand Down Expand Up @@ -145,7 +145,7 @@ func (s *ClientTestSuite) TestPlanClient_GetByPath() {
}
`, targetPlanPath)

s.serveMux.HandleFunc(urlPath, func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get(urlPath, func(w http.ResponseWriter, _ *http.Request) {
_, err = w.Write([]byte(respStr))
s.NoError(err, "wrote response string to writer")
})
Expand Down
4 changes: 2 additions & 2 deletions bonsai/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func (s *ClientTestSuite) TestReleaseClient_All() {
s.serveMux.HandleFunc(bonsai.ReleaseAPIBasePath, func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get(bonsai.ReleaseAPIBasePath, func(w http.ResponseWriter, _ *http.Request) {
respStr := `
{
"releases": [
Expand Down Expand Up @@ -84,7 +84,7 @@ func (s *ClientTestSuite) TestReleaseClient_GetBySlug() {
urlPath, err := url.JoinPath(bonsai.ReleaseAPIBasePath, targetReleaseSlug)
s.NoError(err, "successfully resolved path")

s.serveMux.HandleFunc(urlPath, func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get(urlPath, func(w http.ResponseWriter, _ *http.Request) {
respStr := fmt.Sprintf(`
{
"name": "Elasticsearch 7.2.0",
Expand Down
4 changes: 2 additions & 2 deletions bonsai/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func (s *ClientTestSuite) TestSpaceClient_All() {
s.serveMux.HandleFunc(bonsai.SpaceAPIBasePath, func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get(bonsai.SpaceAPIBasePath, func(w http.ResponseWriter, _ *http.Request) {
respStr := `
{
"spaces": [
Expand Down Expand Up @@ -64,7 +64,7 @@ func (s *ClientTestSuite) TestSpaceClient_GetByPath() {
urlPath, err := url.JoinPath(bonsai.SpaceAPIBasePath, targetSpacePath)
s.NoError(err, "successfully create url path")

s.serveMux.HandleFunc(urlPath, func(w http.ResponseWriter, _ *http.Request) {
s.serveMux.Get(urlPath, func(w http.ResponseWriter, _ *http.Request) {
respStr := fmt.Sprintf(`
{
"path": "%s",
Expand Down

0 comments on commit 96850a6

Please sign in to comment.