Files
warpbox-dev/backend/libs/config/config_test.go
Daniel Legt 74ede000b4 feat: implement configurable background jobs and toggle flags
Introduce environment variables to globally and individually control background jobs:
- `WARPBOX_JOBS_ENABLED` to toggle all background workers.
- `WARPBOX_CLEANUP_ENABLED` to toggle the expired box cleanup job.
- `WARPBOX_THUMBNAIL_ENABLED` to toggle the thumbnail generation job.

Refactor background tasks into a dedicated `backend/libs/jobs` package, allowing jobs to be registered, scheduled, and conditionally run based on the new configuration flags. Additionally, update the default maximum upload size in `.env.example` to 16GB and document the new settings in the README.
2026-05-29 22:25:59 +03:00

52 lines
1.2 KiB
Go

package config
import "testing"
func TestParseMegabytes(t *testing.T) {
tests := map[string]int64{
"0.5": 512 * 1024,
"0.5Mb": 512 * 1024,
"1mb": 1024 * 1024,
"1MB": 1024 * 1024,
"1.5Mb": 1536 * 1024,
" 2 ": 2 * 1024 * 1024,
}
for input, want := range tests {
got, err := parseMegabytes(input)
if err != nil {
t.Fatalf("parseMegabytes(%q) returned error: %v", input, err)
}
if got != want {
t.Fatalf("parseMegabytes(%q) = %d, want %d", input, got, want)
}
}
}
func TestParseMegabytesRejectsInvalidValues(t *testing.T) {
tests := []string{"", "0", "-1", "abc"}
for _, input := range tests {
if _, err := parseMegabytes(input); err == nil {
t.Fatalf("parseMegabytes(%q) returned nil error", input)
}
}
}
func TestEnvBool(t *testing.T) {
t.Setenv("WARPBOX_TEST_BOOL", "false")
if got := envBool("WARPBOX_TEST_BOOL", true); got {
t.Fatalf("envBool() = true, want false")
}
t.Setenv("WARPBOX_TEST_BOOL", "1")
if got := envBool("WARPBOX_TEST_BOOL", false); !got {
t.Fatalf("envBool() = false, want true")
}
t.Setenv("WARPBOX_TEST_BOOL", "not-a-bool")
if got := envBool("WARPBOX_TEST_BOOL", true); !got {
t.Fatalf("envBool() did not fall back to true")
}
}