mirror of
https://github.com/wneessen/apg-go.git
synced 2024-11-25 15:20:50 +01:00
Add tests for HasBeenPwned function
Introduced unit tests for the HasBeenPwned function in the hibp_test.go file. These tests consist of scenarios with both secured and compromised passwords, improving the function's reliability and error handling capabilities.
This commit is contained in:
parent
87f93ddbc6
commit
c5caab0066
1 changed files with 27 additions and 0 deletions
27
hibp_test.go
Normal file
27
hibp_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package apg
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHasBeenPwned(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
password string
|
||||
want bool
|
||||
}{
|
||||
{"Pwned PW", "Test123", true},
|
||||
{"Secure PW", "Cta8mWYmW7O*j1V!YMTS", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := HasBeenPwned(tt.password)
|
||||
if err != nil {
|
||||
t.Errorf("HasBeenPwned() failed: %s", err)
|
||||
}
|
||||
if tt.want != got {
|
||||
t.Errorf("HasBeenPwned() failed, wanted: %t, got: %t", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue