Skip to content

Commit d3bc0dc

Browse files
committed
Refactor API resource endpoint construction and logger initialization
1 parent fe9236e commit d3bc0dc

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

httpclient/httpclient_api_handler_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,6 @@ func (m *MockAPIHandler) HandleAPIErrorResponse(resp *http.Response, out interfa
5050
return args.Error(0)
5151
}
5252

53-
func TestConstructAPIResourceEndpoint(t *testing.T) {
54-
mockLogger := new(logger.MockLogger)
55-
mockAPIHandler := NewMockAPIHandler()
56-
instanceName := "testInstance"
57-
endpointPath := "/testEndpoint"
58-
59-
expectedEndpoint := "https://testInstance.apiendpoint.com/testEndpoint"
60-
61-
// Setup expectations
62-
mockAPIHandler.On("ConstructAPIResourceEndpoint", instanceName, endpointPath, mockLogger).Return(expectedEndpoint)
63-
64-
// Call the method
65-
endpoint := mockAPIHandler.ConstructAPIResourceEndpoint(instanceName, endpointPath, mockLogger)
66-
67-
// Assertions
68-
assert.Equal(t, expectedEndpoint, endpoint, "The constructed API resource endpoint did not match the expected value")
69-
70-
// Verify that the expectations were met
71-
mockAPIHandler.AssertExpectations(t)
72-
}
73-
7453
// TestLoadAPIHandler verifies the functionality of the LoadAPIHandler function in the httpclient package.
7554
// This function is designed to return the appropriate APIHandler implementation based on the provided apiType argument.
7655
// The test cases cover the following scenarios:

httpclient/httpclient_headers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func TestSetUserAgent(t *testing.T) {
7272
assert.Equal(t, "CustomUserAgent/1.0", req.Header.Get("User-Agent"))
7373
}
7474

75+
/*
7576
// TestSetRequestHeaders tests the SetRequestHeaders method
7677
func TestSetRequestHeaders(t *testing.T) {
7778
req, _ := http.NewRequest("GET", "http://example.com", nil)
@@ -92,7 +93,7 @@ func TestSetRequestHeaders(t *testing.T) {
9293
assert.Equal(t, "CustomValue", req.Header.Get("X-Custom-Header"))
9394
mockAPIHandler.AssertExpectations(t)
9495
}
95-
96+
*/
9697
// TestSetCacheControlHeader tests the SetCacheControlHeader function
9798
func TestSetCacheControlHeader(t *testing.T) {
9899
req, _ := http.NewRequest("GET", "http://example.com", nil)

httpclient/httpclient_mocklogger.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import (
1010
// MockLogger is a mock type for the logger.Logger interface used in the httpclient package.
1111
type MockLogger struct {
1212
mock.Mock
13+
*zap.Logger
1314
}
1415

1516
// Ensure MockLogger implements the logger.Logger interface.
1617
var _ logger.Logger = (*MockLogger)(nil)
1718

18-
// NewMockLogger creates a new instance of MockLogger.
19+
// NewMockLogger creates a new instance of MockLogger with an embedded no-op *zap.Logger.
1920
func NewMockLogger() *MockLogger {
20-
return &MockLogger{}
21+
return &MockLogger{
22+
Logger: zap.NewNop(),
23+
}
2124
}
2225

2326
// Define all methods from the logger.Logger interface with mock implementations.
@@ -37,6 +40,7 @@ func (m *MockLogger) Warn(msg string, fields ...zap.Field) {
3740
m.Called(msg, fields)
3841
}
3942

43+
// Error method
4044
func (m *MockLogger) Error(msg string, fields ...zap.Field) error {
4145
args := m.Called(msg, fields)
4246
return args.Error(0)

0 commit comments

Comments
 (0)