Files
coder/coderd/util/tz/tz_test.go
Kyle Carberry 9c12b4ed8e chore: Add nix shell for simple development setup (#3399)
* chore: Add nix shell for simple development setup

This enables contributors using Nix to set up their environment with ease.

* improve nix style, flake output schema

* fix error message

* Update scripts/build_go_slim.sh

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update scripts/build_go_slim.sh

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Add UTC default for timezone and remove unnecessary goreleaser dependency

* Skip TZ test if localtime does not exist

Co-authored-by: Charlie Moog <moogcharlie@gmail.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-08-08 15:49:12 +00:00

47 lines
1.0 KiB
Go

package tz_test
import (
"os"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/coderd/util/tz"
)
//nolint:paralleltest // Environment variables
func Test_TimezoneIANA(t *testing.T) {
//nolint:paralleltest // t.Setenv
t.Run("Env", func(t *testing.T) {
t.Setenv("TZ", "Europe/Dublin")
zone, err := tz.TimezoneIANA()
assert.NoError(t, err)
if assert.NotNil(t, zone) {
assert.Equal(t, "Europe/Dublin", zone.String())
}
})
//nolint:paralleltest // UnsetEnv
t.Run("NoEnv", func(t *testing.T) {
_, err := os.Stat("/etc/localtime")
if runtime.GOOS == "linux" && err != nil {
// Not all Linux operating systems are guaranteed to have localtime!
t.Skip("localtime doesn't exist!")
}
oldEnv, found := os.LookupEnv("TZ")
if found {
require.NoError(t, os.Unsetenv("TZ"))
t.Cleanup(func() {
_ = os.Setenv("TZ", oldEnv)
})
}
zone, err := tz.TimezoneIANA()
assert.NoError(t, err)
assert.NotNil(t, zone)
})
}