Skip to content

Commit

Permalink
Fix casing to export
Browse files Browse the repository at this point in the history
  • Loading branch information
amishas157 committed Nov 19, 2024
1 parent 73268d8 commit 0112a1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions utils/apiclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *APIClient) CallAPI(reqParams RequestParams) (interface{}, error) {
return nil, errors.Wrap(err, "http request creation failed")
}

SetAuthHeaders(reqBody, c.authType, c.authHeaders)
SetAuthHeaders(reqBody, c.AuthType, c.AuthHeaders)
SetHeaders(reqBody, reqParams.Headers)
client := c.HTTP
if client == nil {
Expand Down Expand Up @@ -74,7 +74,7 @@ func (c *APIClient) CallAPI(reqParams RequestParams) (interface{}, error) {
fmt.Printf("Received retryable status %d. Retrying in %v...\n", resp.StatusCode, backoffDuration)
time.Sleep(backoffDuration)
} else {
return nil, fmt.Errorf("Maximum retries reached after receiving status %d", resp.StatusCode)
return nil, fmt.Errorf("maximum retries reached after receiving status %d", resp.StatusCode)
}
} else {
return nil, fmt.Errorf("API request failed with status %d", resp.StatusCode)
Expand Down
9 changes: 2 additions & 7 deletions utils/apiclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_GetURL(t *testing.T) {
func TestGetURL(t *testing.T) {
c := &APIClient{
BaseURL: "https://stellar.org",
}
Expand All @@ -23,13 +23,12 @@ func Test_GetURL(t *testing.T) {
assert.Equal(t, "https://stellar.org/federation?acct=2382376&federation_type=bank_account&swift=BOPBPHMM&type=forward", furl)
}

func Test_CallAPI(t *testing.T) {
func TestCallAPI(t *testing.T) {
testCases := []struct {
name string
mockResponses []httptest.ResponseData
expected interface{}
expectedError string
retries bool
}{
{
name: "status 200 - Success",
Expand All @@ -38,7 +37,6 @@ func Test_CallAPI(t *testing.T) {
},
expected: map[string]interface{}{"data": "Okay Response"},
expectedError: "",
retries: false,
},
{
name: "success with retries - status 429 and 503 then 200",
Expand All @@ -50,7 +48,6 @@ func Test_CallAPI(t *testing.T) {
},
expected: map[string]interface{}{"data": "Third Response"},
expectedError: "",
retries: true,
},
{
name: "failure - status 500",
Expand All @@ -59,7 +56,6 @@ func Test_CallAPI(t *testing.T) {
},
expected: nil,
expectedError: "API request failed with status 500",
retries: false,
},
{
name: "failure - status 401",
Expand All @@ -68,7 +64,6 @@ func Test_CallAPI(t *testing.T) {
},
expected: nil,
expectedError: "API request failed with status 401",
retries: false,
},
}

Expand Down
4 changes: 2 additions & 2 deletions utils/apiclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type HTTP interface {
type APIClient struct {
BaseURL string
HTTP HTTP
authType string
authHeaders map[string]interface{}
AuthType string
AuthHeaders map[string]interface{}
}

type RequestParams struct {
Expand Down
14 changes: 7 additions & 7 deletions utils/apiclient/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_CreateRequestBody_ValidURL(t *testing.T) {
func TestCreateRequestBodyValidURL(t *testing.T) {
// Valid case
req, err := CreateRequestBody("GET", "http://stellar.org")
assert.NotNil(t, req)
assert.NoError(t, err)
}

func Test_CreateRequestBody_InvalidURL(t *testing.T) {
func TestCreateRequestBodyInvalidURL(t *testing.T) {
invalidURL := "://invalid-url"
req, err := CreateRequestBody("GET", invalidURL)
assert.Nil(t, req)
assert.Error(t, err)
assert.Contains(t, err.Error(), "http GET request creation failed")
}

func Test_SetHeaders_ValidHeaders(t *testing.T) {
func TestSetHeadersValidHeaders(t *testing.T) {
req, err := CreateRequestBody("GET", "http://stellar.org")
assert.NoError(t, err)

Expand All @@ -34,7 +34,7 @@ func Test_SetHeaders_ValidHeaders(t *testing.T) {
assert.Equal(t, "GoClient/1.0", req.Header.Get("User-Agent"))
}

func Test_SetHeaders_InvalidHeaders(t *testing.T) {
func TestSetHeadersInvalidHeaders(t *testing.T) {
req, err := CreateRequestBody("GET", "http://stellar.org")
assert.NoError(t, err)

Expand All @@ -51,15 +51,15 @@ func Test_SetHeaders_InvalidHeaders(t *testing.T) {
assert.Equal(t, "Bearer token123", req.Header.Get("Authorization")) // Set correctly
}

type SetAuthHeadersTestCase struct {
type setAuthHeadersTestCase struct {
authType string
args map[string]interface{}
expectedHeader string
expectedError string
}

func Test_SetAuthHeaders(t *testing.T) {
testCases := []SetAuthHeadersTestCase{
func TestSetAuthHeaders(t *testing.T) {
testCases := []setAuthHeadersTestCase{
{
authType: "basic",
args: map[string]interface{}{
Expand Down

0 comments on commit 0112a1d

Please sign in to comment.