From 751c06752f60088c6aa41e184611db647764ea85 Mon Sep 17 00:00:00 2001 From: effoeffi Date: Wed, 20 Mar 2024 13:36:15 +0200 Subject: [PATCH] test env util --- env/util_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 env/util_test.go diff --git a/env/util_test.go b/env/util_test.go new file mode 100644 index 0000000..2980a76 --- /dev/null +++ b/env/util_test.go @@ -0,0 +1,32 @@ +package env_test + +import ( + "os" + "strconv" + "testing" + + "github.com/google/uuid" + "github.com/oasdiff/go-common/env" + "github.com/stretchr/testify/require" +) + +func TestGetEnvWithDefault(t *testing.T) { + + const value = "http://test.me.com" + require.Equal(t, value, env.GetEnvWithDefault("MY_TEST_CONNECTION", value)) +} + +func TestGetEnvIntWithDefault(t *testing.T) { + + const value = 14 + require.Equal(t, value, env.GetEnvIntWithDefault("MY_TEST_CONNECTION", value)) +} + +func TestGetEnvIntWithDefault_Convert(t *testing.T) { + + key := uuid.NewString() + const value = 14 + + os.Setenv(key, strconv.Itoa(value)) + require.Equal(t, value, env.GetEnvIntWithDefault(key, value)) +}