go-hibp/hibp_test.go

41 lines
976 B
Go
Raw Normal View History

2021-09-21 11:21:04 +02:00
package hibp
import (
"testing"
"time"
)
// TestNew tests the New() function
func TestNew(t *testing.T) {
hc := New()
if hc == nil {
t.Errorf("hibp client creation failed")
}
}
2021-09-21 18:21:23 +02:00
// TestNewWithHttpTimeout tests the New() function with the http timeout option
2021-09-21 11:21:04 +02:00
func TestNewWithHttpTimeout(t *testing.T) {
hc := New(WithHttpTimeout(time.Second * 10))
if hc == nil {
t.Errorf("hibp client creation failed")
2021-09-21 11:26:48 +02:00
return
2021-09-21 11:21:04 +02:00
}
if hc.to != time.Second*10 {
t.Errorf("hibp client timeout option was not set properly. Expected %d, got: %d",
time.Second*10, hc.to)
}
}
2021-09-21 18:21:23 +02:00
// TestNewWithPwnedPadding tests the New() function with the PwnedPadding option
func TestNewWithPwnedPadding(t *testing.T) {
hc := New(WithPwnedPadding())
if hc == nil {
t.Errorf("hibp client creation failed")
return
}
if !hc.PwnedPassApiOpts.WithPadding {
t.Errorf("hibp client pwned padding option was not set properly. Expected %v, got: %v",
true, hc.PwnedPassApiOpts.WithPadding)
}
}