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