test: fix some coverage issues, refactored some of the pagination logic to accomplish this (#3674)

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
Andrei Aaron
2025-12-23 19:06:13 +02:00
committed by GitHub
parent 4ad3fad3bc
commit 95b8d65c8a
6 changed files with 154 additions and 46 deletions
+40
View File
@@ -538,5 +538,45 @@ func TestHTPasswdWatcher(t *testing.T) {
So(ok, ShouldBeTrue)
So(present, ShouldBeTrue)
})
Convey("Test htpasswd file with zero users warning", func() {
// Create a buffer to capture log output
logBuffer, multiWriter := test.CreateLogCapturingWriter(os.Stdout)
capturingLogger := log.NewLoggerWithWriter("debug", multiWriter)
username, _ := test.GenerateRandomString()
password, _ := test.GenerateRandomString()
htp := api.NewHTPasswd(capturingLogger)
// Create an empty htpasswd file (zero users)
emptyPath := test.MakeHtpasswdFileFromString(t, "")
// Reload the empty file
err := htp.Reload(emptyPath)
So(err, ShouldBeNil)
// Verify the warning message is logged
So(test.WaitForLogMessages(logBuffer, "loaded htpasswd file appears to have zero users", 1, 5*time.Second),
ShouldBeTrue)
// Verify store is empty
_, present := htp.Get(username)
So(present, ShouldBeFalse)
// Now load a file with a user and verify the info message instead
userPath := test.MakeHtpasswdFileFromString(t, test.GetBcryptCredString(username, password))
err = htp.Reload(userPath)
So(err, ShouldBeNil)
// Verify the info message is logged
So(test.WaitForLogMessages(logBuffer, "loaded htpasswd file", 1, 5*time.Second), ShouldBeTrue)
// Verify user is present
ok, present := htp.Authenticate(username, password)
So(ok, ShouldBeTrue)
So(present, ShouldBeTrue)
})
})
}