Initialize the repository with the core Go backend architecture and a frontend mockup for warpbox.dev, a self-hosted file-sharing application. - Set up Go backend modules for configuration, HTTP server, middleware, handlers, and templates. - Add local development scripts, environment templates, and basic project configuration. - Include a React-based frontend mockup under the docs directory.
35 lines
757 B
Go
35 lines
757 B
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)
|
|
}
|
|
}
|
|
}
|