Created
October 24, 2022 08:44
-
-
Save hauxe/696aa156a2ef025d803709faf1241d6e to your computer and use it in GitHub Desktop.
Generic get environment unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import ( | |
"os" | |
"testing" | |
"github.com/stretchr/testify/require" | |
) | |
func TestGetEnvT(t *testing.T) { | |
t.Run("string", func(t *testing.T) { | |
env := "UNITTEST_GETENVT_STRING" | |
os.Setenv(env, "string") | |
defer os.Unsetenv(env) | |
s := GetEnvT(env, EnvString) | |
require.Equal(t, "string", s) | |
}) | |
t.Run("bool", func(t *testing.T) { | |
env := "UNITTEST_GETENVT_BOOL" | |
os.Setenv(env, "true") | |
defer os.Unsetenv(env) | |
b := GetEnvT(env, EnvBool) | |
require.True(t, b) | |
}) | |
t.Run("int", func(t *testing.T) { | |
env := "UNITTEST_GETENVT_INT" | |
os.Setenv(env, "123") | |
defer os.Unsetenv(env) | |
i := GetEnvT(env, EnvInt) | |
require.Equal(t, 123, i) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment