github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/utils/env_test.go (about) 1 package utils 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestEnvBool(t *testing.T) { 10 cases := []struct { 11 name string 12 envSetName string 13 envSetValue string 14 envLookupName string 15 envDefaultVal bool 16 envRet bool 17 }{ 18 { 19 "Value is true", 20 "EB_A", 21 "true", 22 "EB_A", 23 false, 24 true, 25 }, 26 { 27 "Value is false", 28 "EB_A", 29 "false", 30 "EB_A", 31 true, 32 false, 33 }, 34 { 35 "Value is not set", 36 "EB_A", 37 "true", 38 "EB_B", 39 false, 40 false, 41 }, 42 } 43 44 for _, test := range cases { 45 t.Run(test.name, func(t *testing.T) { 46 t.Setenv(test.envSetName, test.envSetValue) 47 val := EnvBool(test.envLookupName, test.envDefaultVal) 48 assert.Equal(t, test.envRet, val) 49 }) 50 } 51 }