test: add new handler test files for analytics, auth, kobo, library, progress, and sidecar
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSanitizeFilename_NoChange(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
}{
|
||||
{"simple_filename"},
|
||||
{"file_name_123"},
|
||||
{"Document"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := sanitizeFilename(tt.name)
|
||||
assert.Equal(t, tt.name, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeFilename_ReplacesSpecialChars(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"slash", "file/name", "file_name"},
|
||||
{"backslash", "file\\name", "file_name"},
|
||||
{"colon", "file:name", "file_name"},
|
||||
{"asterisk", "file*name", "file_name"},
|
||||
{"question_mark", "file?name", "file_name"},
|
||||
{"quotes", "file\"name", "file_name"},
|
||||
{"less_than", "file<name", "file_name"},
|
||||
{"greater_than", "file>name", "file_name"},
|
||||
{"pipe", "file|name", "file_name"},
|
||||
{"multiple_chars", "a/b\\c:d*e", "a_b_c_d_e"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := sanitizeFilename(tt.input)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeAll_Basic(t *testing.T) {
|
||||
result := sanitizeAll("hello world", "o", "0")
|
||||
assert.Equal(t, "hell0 w0rld", result)
|
||||
}
|
||||
|
||||
func TestSanitizeAll_NoMatch(t *testing.T) {
|
||||
result := sanitizeAll("hello", "x", "y")
|
||||
assert.Equal(t, "hello", result)
|
||||
}
|
||||
|
||||
func TestSanitizeAll_EmptyStrings(t *testing.T) {
|
||||
result := sanitizeAll("", "a", "b")
|
||||
assert.Equal(t, "", result)
|
||||
|
||||
result = sanitizeAll("test", "", "x")
|
||||
assert.Equal(t, "test", result)
|
||||
}
|
||||
Reference in New Issue
Block a user