This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-core/env/env_test.go

37 lines
944 B
Go

package env
import (
"os"
"testing"
)
func TestSetGet(t *testing.T) {
t.Setenv("OLLIE_TEST_VAR", "")
Set("OLLIE_TEST_VAR", "hello")
if got := Get("OLLIE_TEST_VAR"); got != "hello" {
t.Errorf("Get = %q, want %q", got, "hello")
}
}
func TestLoadFile(t *testing.T) {
tmp := t.TempDir()
path := tmp + "/env"
os.WriteFile(path, []byte("OLLIE_LOAD_TEST=from-file\n"), 0644) //nolint:errcheck
t.Setenv("OLLIE_LOAD_TEST", "")
LoadFile(path)
if v := os.Getenv("OLLIE_LOAD_TEST"); v != "from-file" {
t.Errorf("OLLIE_LOAD_TEST = %q, want from-file", v)
}
}
func TestLoadFileNoOverwrite(t *testing.T) {
t.Setenv("OLLIE_NO_OVERWRITE", "existing")
tmp := t.TempDir()
path := tmp + "/env"
os.WriteFile(path, []byte("OLLIE_NO_OVERWRITE=from-file\n"), 0644) //nolint:errcheck
LoadFile(path)
if v := os.Getenv("OLLIE_NO_OVERWRITE"); v != "existing" {
t.Errorf("OLLIE_NO_OVERWRITE = %q, want existing (should not overwrite)", v)
}
}