Files

33 lines
924 B
Go
Raw Permalink Normal View History

2026-09-23 06:13:52 +02:00
package main
import "testing"
func TestEnvInt64(t *testing.T) {
tests := []struct {
name string
value string
fallback int64
want int64
}{
{name: "valid", value: "1234567890123", fallback: 7, want: 1234567890123},
{name: "trimmed", value: " 42 ", fallback: 7, want: 42},
{name: "empty", value: "", fallback: 7, want: 7},
{name: "invalid", value: "not-a-number", fallback: 7, want: 7},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Setenv("COLLABTABLE_TEST_ENV_INT64", test.value)
if got := envInt64("COLLABTABLE_TEST_ENV_INT64", test.fallback); got != test.want {
t.Fatalf("envInt64() = %d, want %d", got, test.want)
}
})
}
}
func TestEnvInt64UsesFallbackWhenUnset(t *testing.T) {
t.Setenv("COLLABTABLE_TEST_ENV_INT64", "")
if got := envInt64("COLLABTABLE_TEST_ENV_INT64_UNSET", 99); got != 99 {
t.Fatalf("envInt64() = %d, want 99", got)
}
}