From 842cc122a512ff31d60a3d7c2e29e2a1cae4fa22 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 12 Apr 2022 22:52:24 +0200 Subject: [PATCH] Fix code smell in WithUserAgent() option detected by SonarQube --- hibp.go | 2 +- hibp_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hibp.go b/hibp.go index 04f2f1a..22ace5e 100644 --- a/hibp.go +++ b/hibp.go @@ -95,7 +95,7 @@ func WithPwnedPadding() Option { // WithUserAgent sets a custom user agent string for the HTTP client func WithUserAgent(a string) Option { if a == "" { - return func(c *Client) {} + return nil } return func(c *Client) { c.ua = a diff --git a/hibp_test.go b/hibp_test.go index a264f86..0dcf795 100644 --- a/hibp_test.go +++ b/hibp_test.go @@ -65,4 +65,10 @@ func TestNewWithUserAgent(t *testing.T) { t.Errorf("hibp client custom user agent was not set properly. Expected %s, got: %s", custUA, hc.ua) } + + hc = New(WithUserAgent("")) + if hc.ua != DefaultUserAgent { + t.Errorf("hibp client custom user agent was not set properly. Expected %s, got: %s", + DefaultUserAgent, hc.ua) + } }