Skip to content

Commit

Permalink
Remove HTTPClient arg from client.New(). (#43)
Browse files Browse the repository at this point in the history
Previously one was always required to provide a web.HTTPClient, which
everyone always just sets to `nil`. If you really want to provide one
use `NewWithCustomHTTPClient()`.

In passing fix some typos and lint errors.
  • Loading branch information
steven-collins-omega authored Aug 9, 2021
1 parent 9d4f411 commit 61152f7
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 16 deletions.
7 changes: 6 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ type SatCon struct {
}

//New creates new SatCon clients
func New(endpointURL string, httpClient web.HTTPClient, authClient auth.AuthClient) (SatCon, error) {
func New(endpointURL string, authClient auth.AuthClient) (SatCon, error) {
return NewWithCustomHTTPClient(endpointURL, nil, authClient)
}

//NewWithCustomHTTPClient creates new SatCon clients with a custom web.HTTPClient
func NewWithCustomHTTPClient(endpointURL string, httpClient web.HTTPClient, authClient auth.AuthClient) (SatCon, error) {
var (
err error
s SatCon
Expand Down
4 changes: 2 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("Client", func() {
})

It("Creates a new SatCon client", func() {
s, err := New(endpointURL, nil, iamClient.Client)
s, err := New(endpointURL, iamClient.Client)
Expect(err).NotTo(HaveOccurred())
Expect(s.Channels).NotTo(BeNil())
Expect(s.Clusters).NotTo(BeNil())
Expand All @@ -41,7 +41,7 @@ var _ = Describe("Client", func() {
})

It("Errors when endpointURL is empty", func() {
s, err := New("", nil, iamClient.Client)
s, err := New("", iamClient.Client)
Expect(err).To(HaveOccurred())
Expect(s.Channels).To(BeNil())
Expect(s.Clusters).To(BeNil())
Expand Down
5 changes: 2 additions & 3 deletions client/web/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package web
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"
Expand Down Expand Up @@ -96,9 +95,9 @@ func CheckResponseForErrors(body []byte) error {
var errorMessage string
errLength := len(errorDetails.Errors)
for i := range errorDetails.Errors {
errorMessage += fmt.Sprintf("%s", errorDetails.Errors[i].Message)
errorMessage += errorDetails.Errors[i].Message
if i < (errLength - 1) {
errorMessage += fmt.Sprint(", ")
errorMessage += ", "
}
}
return errors.New(errorMessage)
Expand Down
7 changes: 4 additions & 3 deletions client/web/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ var _ = Describe("Client", func() {
})

It("Deserializes the response body into the result", func() {
s.DoQuery(requestTemplate, vars, nil, &result)
err := s.DoQuery(requestTemplate, vars, nil, &result)
Expect(err).NotTo(HaveOccurred())
Expect(result.Name).To(Equal(name))
})

Expand Down Expand Up @@ -136,7 +137,7 @@ var _ = Describe("Client", func() {
})
})

Context("When unmarshalling errors", func() {
Context("When unmarshaling errors", func() {
It("Bubbles up the unmarshal error", func() {
err := s.DoQuery(requestTemplate, vars, nil, nil)
_, ok := err.(*json.InvalidUnmarshalError)
Expand Down Expand Up @@ -167,7 +168,7 @@ var _ = Describe("Client", func() {
}

response = &http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(fmt.Sprint(`{"errors": [{"message": "Context creation failed: Your session expired. Sign in again","extensions": {"code": "UNAUTHENTICATED"}}]}`))),
Body: ioutil.NopCloser(bytes.NewBufferString(`{"errors": [{"message": "Context creation failed: Your session expired. Sign in again","extensions": {"code": "UNAUTHENTICATED"}}]}`)),
}

h.DoReturns(response, nil)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.14
require (
github.com/IBM/go-sdk-core/v4 v4.8.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/google/go-cmp v0.5.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
github.com/onsi/ginkgo v1.14.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
Expand Down
2 changes: 1 addition & 1 deletion test/integration/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Channels", func() {
var iamClient *iam.Client
iamClient, err = iam.NewIAMClient(testConfig.APIKey, testConfig.IAMEndpoint)
Expect(err).ToNot(HaveOccurred())
c, _ = client.New(testConfig.SatConEndpoint, nil, iamClient.Client)
c, _ = client.New(testConfig.SatConEndpoint, iamClient.Client)
Expect(c.Channels).NotTo(BeNil())
})

Expand Down
2 changes: 1 addition & 1 deletion test/integration/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Clusters", func() {
var err error
iamClient, err = iam.NewIAMClient(testConfig.APIKey, testConfig.IAMEndpoint)
Expect(err).ToNot(HaveOccurred())
c, _ = client.New(testConfig.SatConEndpoint, nil, iamClient.Client)
c, _ = client.New(testConfig.SatConEndpoint, iamClient.Client)
Expect(c.Clusters).NotTo(BeNil())
})

Expand Down
2 changes: 1 addition & 1 deletion test/integration/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = Describe("Groups", func() {
var err error
iamClient, err = iam.NewIAMClient(testConfig.APIKey, testConfig.IAMEndpoint)
Expect(err).ToNot(HaveOccurred())
c, _ = client.New(testConfig.SatConEndpoint, nil, iamClient.Client)
c, _ = client.New(testConfig.SatConEndpoint, iamClient.Client)
Expect(c.Groups).NotTo(BeNil())
})

Expand Down
2 changes: 1 addition & 1 deletion test/integration/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("Subscriptions", func() {
var err error
iamClient, err = iam.NewIAMClient(testConfig.APIKey, testConfig.IAMEndpoint)
Expect(err).ToNot(HaveOccurred())
c, _ = client.New(testConfig.SatConEndpoint, nil, iamClient.Client)
c, _ = client.New(testConfig.SatConEndpoint, iamClient.Client)
Expect(c.Subscriptions).NotTo(BeNil())

encodedContent := "YXBpVmVyc2lvbjogdjEKa2luZDogUG9kCm1ldGFkYXRhOgogIG5hbWU6IGludGVncmF0aW9uX3Rlc3QKc3BlYzoKICBjb250YWluZXJzOgogIC0gbmFtZTogaW50ZWdyYXRpb25fdGVzdAogICAgaW1hZ2U6IGh0dHBkOmFscGluZQo="
Expand Down
2 changes: 1 addition & 1 deletion test/integration/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _ = Describe("Users", func() {
var err error
iamClient, err = iam.NewIAMClient(testConfig.APIKey, testConfig.IAMEndpoint)
Expect(err).ToNot(HaveOccurred())
c, _ = client.New(testConfig.SatConEndpoint, nil, iamClient.Client)
c, _ = client.New(testConfig.SatConEndpoint, iamClient.Client)
Expect(c.Clusters).NotTo(BeNil())
})

Expand Down
4 changes: 2 additions & 2 deletions test/integration/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = Describe("Versions", func() {
var err error
iamClient, err = iam.NewIAMClient(testConfig.APIKey, testConfig.IAMEndpoint)
Expect(err).ToNot(HaveOccurred())
c, _ = client.New(testConfig.SatConEndpoint, nil, iamClient.Client)
c, _ = client.New(testConfig.SatConEndpoint, iamClient.Client)
Expect(c.Versions).NotTo(BeNil())

encodedContent := "YXBpVmVyc2lvbjogdjEKa2luZDogUG9kCm1ldGFkYXRhOgogIG5hbWU6IGludGVncmF0aW9uX3Rlc3QKc3BlYzoKICBjb250YWluZXJzOgogIC0gbmFtZTogaW50ZWdyYXRpb25fdGVzdAogICAgaW1hZ2U6IGh0dHBkOmFscGluZQo="
Expand All @@ -48,7 +48,7 @@ var _ = Describe("Versions", func() {
})

It("Gets our channel version by name to show it does not exist, creates a channel, creates a "+
"channel version, gets the versionby name, removes the version, removes the channel, then tries "+
"channel version, gets the version by name, removes the version, removes the channel, then tries "+
"to get the version by name again to show it no longer exists", func() {
// Demonstrate channel version does not exist for the arguments of the current channelName and versionName
version, err := c.Versions.ChannelVersionByName(testConfig.OrgID, channelName, versionName)
Expand Down

0 comments on commit 61152f7

Please sign in to comment.