2 Commits

Author SHA1 Message Date
Nikola Jokic 72647ae108 Fix logger propagation (#85)
Go / test (push) Has been cancelled
Go / mocks (push) Has been cancelled
Go / lint (push) Has been cancelled
E2E / Basic E2E (push) Has been cancelled
Go / fmt (push) Has been cancelled
2026-04-24 15:50:32 +02:00
dependabot[bot] 02ad99e7fe Bump the actions group with 2 updates (#81)
Bumps the actions group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action).


Updates `actions/checkout` from 5 to 6
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

Updates `golangci/golangci-lint-action` from 8.0.0 to 9.2.0
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/4afd733a84b1f43292c63897423277bb7f4313a9...1e7e51e771db61008b38414a730f564565cf7c20)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: golangci/golangci-lint-action
  dependency-version: 9.2.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-24 10:37:38 +02:00
3 changed files with 60 additions and 8 deletions
+5 -5
View File
@@ -19,7 +19,7 @@ jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
@@ -32,7 +32,7 @@ jobs:
mocks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
@@ -45,13 +45,13 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20
with:
only-new-issues: true
version: v2.5.0
@@ -59,7 +59,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
+1 -3
View File
@@ -120,9 +120,7 @@ func (o *httpClientOption) newRetryableHTTPClient() (*retryablehttp.Client, erro
retryClient.HTTPClient.Timeout = o.timeout
}
if retryClient.Logger == nil {
retryClient.Logger = o.logger
}
retryClient.Logger = o.logger
transport, ok := retryClient.HTTPClient.Transport.(*http.Transport)
if !ok {
+54
View File
@@ -3,6 +3,7 @@ package scaleset
import (
"encoding/json"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"net/url"
@@ -156,6 +157,59 @@ func TestUserAgent(t *testing.T) {
assert.Equal(t, want, got)
}
func TestWithLogger(t *testing.T) {
newJSONHandler := func() slog.Handler {
return slog.NewJSONHandler(
io.Discard,
&slog.HandlerOptions{
AddSource: true,
Level: slog.LevelError,
},
)
}
t.Run("WithLogger(nil) sets a discard logger on raw httpClientOption", func(t *testing.T) {
opts := httpClientOption{}
WithLogger(nil)(&opts)
require.NotNil(t, opts.logger, "WithLogger(nil) should set a discard logger, not leave it nil")
assert.Equal(t, slog.DiscardHandler, opts.logger.Handler(), "WithLogger(nil) should set a discard logger handler")
})
t.Run("WithLogger(customLogger) assigns the provided logger", func(t *testing.T) {
handler := newJSONHandler()
customLogger := slog.New(handler)
opts := httpClientOption{}
WithLogger(customLogger)(&opts)
require.Equal(t, customLogger, opts.logger, "WithLogger should assign the provided logger")
assert.Equal(t, handler, opts.logger.Handler(), "WithLogger should set the provided logger handler")
})
t.Run("WithLogger(nil) propagates discard logger to retryable HTTP client", func(t *testing.T) {
opts := httpClientOption{}
WithLogger(nil)(&opts)
client, err := opts.newRetryableHTTPClient()
require.NoError(t, err)
assert.NotNil(t, client.Logger, "retryable client should have logger set from WithLogger(nil)")
logger, ok := client.Logger.(*slog.Logger)
require.True(t, ok, "retryable client logger should be a *slog.Logger")
assert.Same(t, opts.logger, logger, "retryable client logger should be the same logger set by WithLogger(nil)")
assert.Equal(t, slog.DiscardHandler, logger.Handler(), "retryable client logger should be a discard logger from WithLogger(nil)")
})
t.Run("WithLogger(customLogger) propagates custom logger to retryable HTTP client", func(t *testing.T) {
handler := newJSONHandler()
customLogger := slog.New(handler)
opts := httpClientOption{}
WithLogger(customLogger)(&opts)
client, err := opts.newRetryableHTTPClient()
require.NoError(t, err)
assert.NotNil(t, client.Logger, "retryable client should have logger set")
logger, ok := client.Logger.(*slog.Logger)
require.True(t, ok, "retryable client logger should be a *slog.Logger")
assert.Equal(t, handler, logger.Handler(), "retryable client logger should be the custom logger from WithLogger")
})
}
// TestWithRetryableHTTPClient verifies that a custom retryable HTTP client
// provided via WithRetryableHTTPClient is actually used instead of the built-in one
func TestWithRetryableHTTPClient(t *testing.T) {