timezone test: source order and fall-through between $TZ, link and /etc/timezone
Four cases where more than one source is live: $TZ beats the link, an invalid $TZ falls through to the link, the link beats /etc/timezone, an invalid link falls through to /etc/timezone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+11
−0
timezone_test.go+11 −0
diff --git a/timezone_test.go b/timezone_test.go| index daab65bf0..4c0e22aac 100644 |
| --- a/timezone_test.go |
| +++ b/timezone_test.go |
| @@ -16,6 +16,12 @@ func TestLocalTimezone(t *testing.T) { |
| return "" |
| } |
| } |
| + link := func(target string) func(string) (string, error) { |
| + return func(string) (string, error) { return target, nil } |
| + } |
| + file := func(body string) func(string) ([]byte, error) { |
| + return func(string) ([]byte, error) { return []byte(body), nil } |
| + } |
| cases := []struct { |
| name string |
| getenv func(string) string |
| @@ -36,6 +42,11 @@ func TestLocalTimezone(t *testing.T) { |
| {"TZ posixrules path", env("/usr/share/zoneinfo/posixrules"), noLink, noFile, ""}, |
| {"TZ POSIX rule string", env("EST5EDT,M3.2.0,M11.1.0"), noLink, noFile, ""}, |
| {"nothing", env(""), noLink, noFile, ""}, |
| + // Source order and fall-through: more than one source is live. |
| + {"TZ beats link", env("Europe/London"), link("/usr/share/zoneinfo/Asia/Tokyo"), noFile, "Europe/London"}, |
| + {"invalid TZ falls through to link", env("EST5EDT,M3.2.0,M11.1.0"), link("/usr/share/zoneinfo/Asia/Tokyo"), noFile, "Asia/Tokyo"}, |
| + {"link beats etc/timezone", env(""), link("/usr/share/zoneinfo/Asia/Tokyo"), file("Europe/Paris\n"), "Asia/Tokyo"}, |
| + {"invalid link falls through to etc/timezone", env(""), link("/usr/share/zoneinfo/posixrules"), file("Europe/Paris\n"), "Europe/Paris"}, |
| } |
| for _, c := range cases { |
| if got := localTimezone(c.getenv, c.readlink, c.readFile); got != c.want { |