github.com/vishnusomank/figtree@v0.1.0/stop_test.go (about) 1 package figtree 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestOptionsStopConfigD3(t *testing.T) { 12 opts := TestOptions{} 13 require.NoError(t, os.Chdir("d1/d2/d3")) 14 t.Cleanup(func() { 15 _ = os.Chdir("../../..") 16 }) 17 18 arr1 := []StringOption{} 19 arr1 = append(arr1, StringOption{tSrc("stop.yml", 3, 5), true, "d3arr1val1"}) 20 arr1 = append(arr1, StringOption{tSrc("stop.yml", 4, 5), true, "d3arr1val2"}) 21 arr1 = append(arr1, StringOption{tSrc("../stop.yml", 5, 5), true, "d2arr1val1"}) 22 arr1 = append(arr1, StringOption{tSrc("../stop.yml", 6, 5), true, "d2arr1val2"}) 23 24 expected := TestOptions{ 25 String1: StringOption{tSrc("stop.yml", 1, 7), true, "d3str1val1"}, 26 LeaveEmpty: StringOption{}, 27 Array1: arr1, 28 Map1: map[string]StringOption{ 29 "key1": {tSrc("../stop.yml", 8, 9), true, "d2map1val1"}, 30 "key2": {tSrc("stop.yml", 6, 9), true, "d3map1val2"}, 31 "key3": {tSrc("stop.yml", 7, 9), true, "d3map1val3"}, 32 }, 33 Int1: IntOption{tSrc("stop.yml", 8, 7), true, 333}, 34 Float1: Float32Option{tSrc("stop.yml", 9, 9), true, 3.33}, 35 Bool1: BoolOption{tSrc("stop.yml", 10, 8), true, true}, 36 } 37 38 fig := newFigTreeFromEnv() 39 err := fig.LoadAllConfigs("stop.yml", &opts) 40 assert.NoError(t, err) 41 assert.Exactly(t, expected, opts) 42 } 43 44 func TestOptionsStopConfigD2(t *testing.T) { 45 opts := TestOptions{} 46 require.NoError(t, os.Chdir("d1/d2")) 47 t.Cleanup(func() { 48 _ = os.Chdir("../..") 49 }) 50 51 arr1 := []StringOption{} 52 arr1 = append(arr1, StringOption{tSrc("stop.yml", 5, 5), true, "d2arr1val1"}) 53 arr1 = append(arr1, StringOption{tSrc("stop.yml", 6, 5), true, "d2arr1val2"}) 54 55 expected := TestOptions{ 56 String1: StringOption{tSrc("stop.yml", 3, 7), true, "d2str1val1"}, 57 LeaveEmpty: StringOption{}, 58 Array1: arr1, 59 Map1: map[string]StringOption{ 60 "key1": {tSrc("stop.yml", 8, 9), true, "d2map1val1"}, 61 "key2": {tSrc("stop.yml", 9, 9), true, "d2map1val2"}, 62 }, 63 Int1: IntOption{tSrc("stop.yml", 10, 7), true, 222}, 64 Float1: Float32Option{tSrc("stop.yml", 11, 9), true, 2.22}, 65 Bool1: BoolOption{tSrc("stop.yml", 12, 8), true, false}, 66 } 67 68 fig := newFigTreeFromEnv() 69 err := fig.LoadAllConfigs("stop.yml", &opts) 70 assert.NoError(t, err) 71 assert.Exactly(t, expected, opts) 72 } 73 74 func TestBuiltinStopConfigD3(t *testing.T) { 75 opts := TestBuiltin{} 76 require.NoError(t, os.Chdir("d1/d2/d3")) 77 t.Cleanup(func() { 78 _ = os.Chdir("../../..") 79 }) 80 81 arr1 := []string{} 82 arr1 = append(arr1, "d3arr1val1") 83 arr1 = append(arr1, "d3arr1val2") 84 arr1 = append(arr1, "d2arr1val1") 85 arr1 = append(arr1, "d2arr1val2") 86 87 expected := TestBuiltin{ 88 String1: "d3str1val1", 89 LeaveEmpty: "", 90 Array1: arr1, 91 Map1: map[string]string{ 92 "key1": "d2map1val1", 93 "key2": "d3map1val2", 94 "key3": "d3map1val3", 95 }, 96 Int1: 333, 97 Float1: 3.33, 98 Bool1: true, 99 } 100 101 fig := newFigTreeFromEnv() 102 err := fig.LoadAllConfigs("stop.yml", &opts) 103 assert.NoError(t, err) 104 assert.Exactly(t, expected, opts) 105 } 106 107 func TestBuiltinStopConfigD2(t *testing.T) { 108 opts := TestBuiltin{} 109 require.NoError(t, os.Chdir("d1/d2")) 110 t.Cleanup(func() { 111 _ = os.Chdir("../..") 112 }) 113 114 arr1 := []string{} 115 arr1 = append(arr1, "d2arr1val1") 116 arr1 = append(arr1, "d2arr1val2") 117 118 expected := TestBuiltin{ 119 String1: "d2str1val1", 120 LeaveEmpty: "", 121 Array1: arr1, 122 Map1: map[string]string{ 123 "key1": "d2map1val1", 124 "key2": "d2map1val2", 125 }, 126 Int1: 222, 127 Float1: 2.22, 128 Bool1: false, 129 } 130 131 fig := newFigTreeFromEnv() 132 err := fig.LoadAllConfigs("stop.yml", &opts) 133 assert.NoError(t, err) 134 assert.Exactly(t, expected, opts) 135 }