MCPcopy Create free account
hub / github.com/ddev/ddev / TestGetTimezone

Function TestGetTimezone

pkg/util/utils_test.go:252–284  ·  view source on GitHub ↗

TestGetTimezone tests GetTimezone

(t *testing.T)

Source from the content-addressed store, hash-verified

250
251// TestGetTimezone tests GetTimezone
252func TestGetTimezone(t *testing.T) {
253 testCases := []struct {
254 description string
255 input string
256 result string
257 error string
258 }{
259 {"$TZ env var", "Europe/London", "Europe/London", ""},
260 {"Linux /etc/localtime symlink", "/usr/share/zoneinfo/Europe/London", "Europe/London", ""},
261 {"Linux /etc/localtime posix symlink", "/usr/share/zoneinfo/posix/Europe/London", "Europe/London", ""},
262 {"Linux /etc/localtime right symlink", "/usr/share/zoneinfo/right/Europe/London", "Europe/London", ""},
263 {"/etc/localtime is not a symlink", "/etc/localtime", "", "unable to read timezone from /etc/localtime"},
264 {"macOS /etc/localtime symlink", "/var/db/timezone/zoneinfo/Europe/London", "Europe/London", ""},
265 {"macOS Sonoma /etc/localtime symlink", "/private/var/db/timezone/tz/2024a.1.0/zoneinfo/Europe/London", "Europe/London", ""},
266 {"macOS Sequoia /etc/localtime symlink", "/usr/share/zoneinfo.default/Europe/London", "Europe/London", ""},
267 {"Case-insensitive search for /zoneinfo/ in the path", "/path/to/TestZoneInfoTest/Europe/London", "Europe/London", ""},
268 {"Timezone has wrong format", "/Europe/London", "", "unable to read timezone from /Europe/London"},
269 {"Not real timezone", "Europe/Test", "", "unable to read timezone from Europe/Test"},
270 }
271
272 for _, tc := range testCases {
273 t.Run(tc.description, func(t *testing.T) {
274 timezone, err := util.GetTimezone(tc.input)
275 require.Equal(t, tc.result, timezone)
276 if tc.error == "" {
277 require.NoError(t, err)
278 } else {
279 require.Error(t, err)
280 require.Contains(t, err.Error(), tc.error)
281 }
282 })
283 }
284}
285
286// compareSlices checks if two slices are equal after sorting them.
287func compareSlices(a, b []string) bool {

Callers

nothing calls this directly

Calls 2

GetTimezoneFunction · 0.92
ErrorMethod · 0.80

Tested by

no test coverage detected