Files
Memoh/internal/containerd/timezone_test.go
T
BBQ 4fc0ca5110 fix(container): propagate host timezone to all containers
Replace TZ env var with /etc/localtime bind-mount in docker-compose
and inject timezone spec opts into containerd bot containers.
2026-02-20 03:22:31 +08:00

37 lines
798 B
Go

package containerd
import (
"os"
"testing"
)
func TestTimezoneSpecOpts_WithTZ(t *testing.T) {
t.Setenv("TZ", "Asia/Shanghai")
opts := TimezoneSpecOpts()
if _, err := os.Stat("/etc/localtime"); err == nil {
if len(opts) < 1 {
t.Fatal("expected at least mount opt when /etc/localtime exists")
}
}
found := false
for range opts {
found = true
}
if !found {
t.Fatal("expected at least one spec opt when TZ is set")
}
}
func TestTimezoneSpecOpts_WithoutTZ(t *testing.T) {
t.Setenv("TZ", "")
opts := TimezoneSpecOpts()
for _, opt := range opts {
if opt == nil {
t.Fatal("unexpected nil spec opt")
}
}
if _, err := os.Stat("/etc/localtime"); err != nil && len(opts) != 0 {
t.Fatalf("expected no opts when /etc/localtime absent and TZ empty, got %d", len(opts))
}
}