Fix code smell in WithUserAgent() option detected by SonarQube

This commit is contained in:
Winni Neessen 2022-04-12 22:52:24 +02:00
parent 6a561b0f7a
commit 842cc122a5
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D
2 changed files with 7 additions and 1 deletions

View file

@ -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

View file

@ -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)
}
}