fix: restore int64 environment parsing
Docker / Docker Build & Push (push) Successful in 3m32s
Lint / Lint (push) Successful in 27s
Tests / Go backend (push) Successful in 30s
Tests / Dashboard checks (push) Successful in 35s

This commit is contained in:
Gabriel20xx committed 2026-09-23 06:13:52 +02:00
1 parent a4f897572c
commit 775a5520b6
2 files changed
+54

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
package main
import (
"os"
"strconv"
"strings"
)
// envInt64 returns the parsed environment value or fallback when the variable
// is unset, empty, or not a valid base-10 int64.
func envInt64(name string, fallback int64) int64 {
value := strings.TrimSpace(os.Getenv(name))
if value == "" {
return fallback
}
parsed, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return fallback
}
return parsed
}
+33
View File
@@ -0,0 +1,33 @@
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)
}
}