Skip to content

Commit

Permalink
linting/style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Aug 10, 2021
1 parent b2f75bf commit 0c39f09
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
14 changes: 7 additions & 7 deletions pkg/common/webclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var _ = Describe("WebClient", func() {
It("should return an error", func() {
server.AppendHandlers(ghttp.RespondWith(http.StatusOK, "invalid json"))
res := &mockResponse{}
err := webclient.GetJson(server.URL(), &res)
err := webclient.GetJSON(server.URL(), &res)
Expect(server.ReceivedRequests()).Should(HaveLen(1))
Expect(err).To(MatchError("invalid character 'i' looking for beginning of value"))
Expect(res.Status).To(BeEmpty())
Expand All @@ -32,7 +32,7 @@ var _ = Describe("WebClient", func() {
It("should return an error", func() {
server.AppendHandlers(ghttp.RespondWith(http.StatusOK, nil))
res := &mockResponse{}
err := webclient.GetJson(server.URL(), &res)
err := webclient.GetJSON(server.URL(), &res)
Expect(server.ReceivedRequests()).Should(HaveLen(1))
Expect(err).To(MatchError("unexpected end of JSON input"))
Expect(res.Status).To(BeEmpty())
Expand All @@ -42,7 +42,7 @@ var _ = Describe("WebClient", func() {
It("should deserialize GET response", func() {
server.AppendHandlers(ghttp.RespondWithJSONEncoded(http.StatusOK, mockResponse{Status: "OK"}))
res := &mockResponse{}
err := webclient.GetJson(server.URL(), &res)
err := webclient.GetJSON(server.URL(), &res)
Expect(server.ReceivedRequests()).Should(HaveLen(1))
Expect(err).ToNot(HaveOccurred())
Expect(res.Status).To(Equal("OK"))
Expand Down Expand Up @@ -100,22 +100,22 @@ var _ = Describe("WebClient", func() {
ghttp.RespondWithJSONEncoded(http.StatusOK, &mockResponse{Status: "That's Numberwang!"})),
)

err := webclient.PostJson(server.URL(), &req, &res)
err := webclient.PostJSON(server.URL(), &req, &res)
Expect(server.ReceivedRequests()).Should(HaveLen(1))
Expect(err).ToNot(HaveOccurred())
Expect(res.Status).To(Equal("That's Numberwang!"))
})

It("should return error on error status responses", func() {
server.AppendHandlers(ghttp.RespondWith(404, "Not found!"))
err := webclient.PostJson(server.URL(), &mockRequest{}, &mockResponse{})
err := webclient.PostJSON(server.URL(), &mockRequest{}, &mockResponse{})
Expect(server.ReceivedRequests()).Should(HaveLen(1))
Expect(err).To(MatchError("got HTTP 404 Not Found"))
})

It("should return error on invalid request", func() {
server.AppendHandlers(ghttp.VerifyRequest("POST", "/"))
err := webclient.PostJson(server.URL(), func() {}, &mockResponse{})
err := webclient.PostJSON(server.URL(), func() {}, &mockResponse{})
Expect(server.ReceivedRequests()).Should(HaveLen(0))
Expect(err).To(MatchError("error creating payload: json: unsupported type: func()"))
})
Expand All @@ -127,7 +127,7 @@ var _ = Describe("WebClient", func() {
ghttp.RespondWithJSONEncoded(http.StatusOK, res)),
)

err := webclient.PostJson(server.URL(), nil, &[]bool{})
err := webclient.PostJSON(server.URL(), nil, &[]bool{})
Expect(server.ReceivedRequests()).Should(HaveLen(1))
Expect(err).To(MatchError("json: cannot unmarshal object into Go value of type []bool"))
Expect(webclient.ErrorBody(err)).To(MatchJSON(`{"Status":"cool skirt"}`))
Expand Down
16 changes: 8 additions & 8 deletions pkg/common/webclient/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
// JsonContentType is the default mime type for JSON
const JsonContentType = "application/json"

// DefaultJsonClient is the singleton instance of WebClient using http.DefaultClient
var DefaultJsonClient = NewJSONClient()
// DefaultJSONClient is the singleton instance of WebClient using http.DefaultClient
var DefaultJSONClient = NewJSONClient()

// GetJson fetches url using GET and unmarshals into the passed response using DefaultJsonClient
func GetJson(url string, response interface{}) error {
return DefaultJsonClient.Get(url, response)
// GetJSON fetches url using GET and unmarshals into the passed response using DefaultJSONClient
func GetJSON(url string, response interface{}) error {
return DefaultJSONClient.Get(url, response)
}

// PostJson sends request as JSON and unmarshals the response JSON into the supplied struct using DefaultJsonClient
func PostJson(url string, request interface{}, response interface{}) error {
return DefaultJsonClient.Post(url, request, response)
// PostJSON sends request as JSON and unmarshals the response JSON into the supplied struct using DefaultJSONClient
func PostJSON(url string, request interface{}, response interface{}) error {
return DefaultJSONClient.Post(url, request, response)
}

// NewJSONClient returns a WebClient using the default http.Client and JSON serialization
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var _ = Describe("services", func() {
service, err := serviceRouter.Locate(configURL)
Expect(err).NotTo(HaveOccurred())

if httpService, isHttpService := service.(types.HTTPService); isHttpService {
if httpService, isHTTPService := service.(types.HTTPService); isHTTPService {
httpmock.ActivateNonDefault(httpService.HTTPClient())
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/services/telegram/telegram_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (c *Client) getErrorResponse(err error) error {
errResponse := &ErrorResponse{}
if c.WebClient.ErrorResponse(err, errResponse) {
return errResponse
} else {
return err
}
return err
}

0 comments on commit 0c39f09

Please sign in to comment.