Add tests for auth, rate limiting, security, and util
This commit is contained in:
40
internal/util/util_test.go
Normal file
40
internal/util/util_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHumanSize(t *testing.T) {
|
||||
tests := []struct {
|
||||
in int64
|
||||
want string
|
||||
}{
|
||||
{0, "0 B"},
|
||||
{1, "1 B"},
|
||||
{1023, "1023 B"},
|
||||
{1024, "1.0 KB"},
|
||||
{1024 * 1024, "1.0 MB"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
if got := HumanSize(tt.in); got != tt.want {
|
||||
t.Fatalf("HumanSize(%d) = %q, want %q", tt.in, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeFilename(t *testing.T) {
|
||||
if got := SafeFilename(" hello.txt "); got != "hello.txt" {
|
||||
t.Fatalf("expected trimmed filename, got %q", got)
|
||||
}
|
||||
|
||||
// Strips control characters, quotes, and backslashes.
|
||||
in := "a\n\rb\t\"c\\d"
|
||||
got := SafeFilename(in)
|
||||
if got != "abcd" {
|
||||
t.Fatalf("SafeFilename(%q) = %q, want %q", in, got, "abcd")
|
||||
}
|
||||
|
||||
// Empty after sanitization becomes default.
|
||||
if got := SafeFilename("\n\r\t"); got != "file" {
|
||||
t.Fatalf("expected default filename, got %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user