github.com/vshn/k8ify@v1.1.2-0.20240502214202-6c9ed3ef0bf4/pkg/util/configutils_test.go (about) 1 package util_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/vshn/k8ify/pkg/util" 8 ) 9 10 func TestSubConfigEmpty(t *testing.T) { 11 actual := util.SubConfig( 12 map[string]string{}, 13 "myapp", "root") 14 expected := map[string]string{} 15 assert.Equal(t, expected, actual) 16 } 17 18 func TestSubConfigRoot(t *testing.T) { 19 actual := util.SubConfig( 20 map[string]string{"myapp": "value"}, 21 "myapp", "root") 22 expected := map[string]string{"root": "value"} 23 assert.Equal(t, expected, actual) 24 } 25 26 func TestSubConfigRootAnd(t *testing.T) { 27 util.SubConfig( 28 map[string]string{ 29 "myapp": "value", 30 "myapp.root": "other", 31 }, 32 "myapp", "root") 33 34 // This is undefined behavior 35 } 36 37 func TestSubConfig(t *testing.T) { 38 actual := util.SubConfig( 39 map[string]string{ 40 "myapp.one": "foo", 41 "myapp.two": "bar", 42 "myapp.three": "baz", 43 }, 44 "myapp", "root") 45 expected := map[string]string{ 46 "one": "foo", 47 "two": "bar", 48 "three": "baz", 49 } 50 assert.Equal(t, expected, actual) 51 } 52 53 func TestConfigGetInt32(t *testing.T) { 54 config := map[string]string{ 55 "num": "1", 56 "str": "foo", 57 } 58 59 assert.Equal(t, int32(1), util.ConfigGetInt32(config, "num", 99)) 60 assert.Equal(t, int32(88), util.ConfigGetInt32(config, "str", 88)) 61 assert.Equal(t, int32(77), util.ConfigGetInt32(config, "zzz", 77)) 62 } 63 64 func TestIsTruthy(t *testing.T) { 65 assert := assert.New(t) 66 assert.True(util.IsTruthy("true")) 67 assert.True(util.IsTruthy("True")) 68 assert.True(util.IsTruthy("TRUE")) 69 assert.True(util.IsTruthy("yes")) 70 assert.True(util.IsTruthy("YES")) 71 assert.True(util.IsTruthy("1")) 72 73 assert.False(util.IsTruthy("false")) 74 assert.False(util.IsTruthy("False")) 75 assert.False(util.IsTruthy("FALSE")) 76 assert.False(util.IsTruthy("no")) 77 assert.False(util.IsTruthy("NO")) 78 assert.False(util.IsTruthy("0")) 79 }