From 38ff59f2b89da1b20bdc56521e8f591f832ba229 Mon Sep 17 00:00:00 2001 From: The_Spider Date: Fri, 18 Mar 2022 09:47:55 -0500 Subject: [PATCH] Adds 2 init tests --- cmd/go-temper/init_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 cmd/go-temper/init_test.go diff --git a/cmd/go-temper/init_test.go b/cmd/go-temper/init_test.go new file mode 100644 index 0000000..b1e5f14 --- /dev/null +++ b/cmd/go-temper/init_test.go @@ -0,0 +1,36 @@ +package main + +import ( + "os" + "testing" +) + +func TestGetEnvString(t *testing.T) { + os.Unsetenv("TEST_ENV") + testAnswer := getEnvString("TEST_ENV", "success") + if testAnswer != "success" { + t.Errorf("getEnvString() failed to return the expected result, got: %s, wanted: %s.", testAnswer, "success") + } + + os.Setenv("TEST_ENV", "42") + testAnswer = getEnvString("TEST_ENV", "success") + if testAnswer != "42" { + t.Errorf("getEnvString() failed to return the expected result, got: %s, wanted: %s", testAnswer, "42") + } + + return +} + +func TestGetEnvInt(t *testing.T) { + os.Unsetenv("TEST_ENV") + testAnswer := getEnvInt("TEST_ENV", 9500) + if testAnswer != 9500 { + t.Errorf("getEnvInt() failed to return the expected result, got: %v, wanted: %s", testAnswer, "9500") + } + + os.Setenv("TEST_ENV", "9000") + testAnswer = getEnvInt("TEST_ENV", 9500) + if testAnswer != 9000 { + t.Errorf("getEnvInt() failed to return the expected result, got: %v, wanted: %s", testAnswer, "9000") + } +} \ No newline at end of file