package common

import (
	"log"
	"os"
	"testing"
)

func assertString(t *testing.T, got, want string) {
	t.Helper()
	if got != want {
		log.Fatalf("Assertion failed. Got: %s want: %s", got, want)
	}
}

func TestGetDefaultEnv(t *testing.T) {

	t.Run("test key exists", func(t *testing.T) {
		//Setup
		want := "test value"
		os.Setenv("TEST_KEY", want)
		got := GetDefaultEnv("TEST_KEY", "")
		assertString(t, got, want)
		os.Unsetenv("TEST_KEY")
	})

	t.Run("key does not exists", func(t *testing.T) {
		//Setup
		want := "another test value"
		got := GetDefaultEnv("TEST_KEY", want)
		assertString(t, got, want)
	})

	t.Run("key maps to empty value", func(t *testing.T) {
		//Setup
		want := ""
		got := GetDefaultEnv("TEST_EMPTY_KEY", want)
		assertString(t, got, want)
	})
}
