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 TestGetEnvBool(t *testing.T) {
	os.Unsetenv("TEST_ENV")
	testAnswer := getEnvBool("TEST_ENV", true)
	if testAnswer == false {
		t.Errorf("getEnvBool() failed to return the expected result, got: %v, wanted: %s", testAnswer, "false")
	}

	os.Setenv("TEST_ENV", "true")
	testAnswer = getEnvBool("TEST_ENV", true)
	if testAnswer == false {
		t.Errorf("getEnvBool() failed to return the expected result, got: %v, wanted: %s", testAnswer, "false")
	}
}

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")
	}
}

func TestGetEnvFloat64(t *testing.T) {
	os.Unsetenv("TEST_ENV")
	testAnswer := getEnvFloat64("TEST_ENV", 9500)
	if testAnswer != 9500 {
		t.Errorf("getEnvFloat64() failed to return the expected result, got: %v, wanted: %s", testAnswer, "9500")
	}

	os.Setenv("TEST_ENV", "9000")
	testAnswer = getEnvFloat64("TEST_ENV", 9500)
	if testAnswer != 9000 {
		t.Errorf("getEnvFloat64() failed to return the expected result, got: %v, wanted: %s", testAnswer, "9000")
	}
}