Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions radar.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func WithLogger(logger *slog.Logger) func(*RadarClient) {
}
}

// WithClient configures a client for RadarClient.
func WithClient(httpClient *http.Client) func(*RadarClient) {
return func(r *RadarClient) {
r.web = httpClient
}
}

// Returns an instance of RadarClient which can be used to interact with the
// radar server.
func NewRadarClient(opts ...func(*RadarClient)) *RadarClient {
Expand All @@ -77,6 +84,10 @@ func (radar *RadarClient) GetLogger() *slog.Logger {
return radar.log
}

func (radar *RadarClient) GetClient() *http.Client {
return radar.web
}

func (radar *RadarClient) GetTimeout() int {
return radar.timeout
}
Expand Down
13 changes: 13 additions & 0 deletions radar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package radarapi

import (
"log/slog"
"net/http"
"os"
"testing"
"time"
)

func TestWithTimeout(t *testing.T) {
Expand All @@ -25,3 +27,14 @@ func TestWithLoggerLevel(t *testing.T) {
t.Errorf("expected a max log level of warn, got debug")
}
}

func TestWithClient(t *testing.T) {
var (
expect = 1312 * time.Second
client = &http.Client{Timeout: 1312 * time.Second}
)
radarClient := NewRadarClient(WithClient(client))
if radarClient.GetClient().Timeout != expect {
t.Errorf("expected timeout of 1312 seconds")
Comment thread
decentral1se marked this conversation as resolved.
}
}