From c5caab0066e9ffa28d4d25d0064460ce9bcb740d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 12 Mar 2024 19:09:51 +0100 Subject: [PATCH] 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. --- hibp_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 hibp_test.go diff --git a/hibp_test.go b/hibp_test.go new file mode 100644 index 0000000..f890c1d --- /dev/null +++ b/hibp_test.go @@ -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) + } + }) + } +}