github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/pkg/envutil/envutil_test.go (about) 1 package envutil 2 3 import ( 4 "sort" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestMergeEnv(t *testing.T) { 11 type test struct { 12 description string 13 first []string 14 second []string 15 expectedResult []string 16 } 17 18 tests := []test{ 19 { 20 description: "Merging two distinct env variables", 21 first: []string{"VAR_ONE=foo"}, 22 second: []string{"VAR_TWO=bar"}, 23 expectedResult: []string{"VAR_ONE=foo", "VAR_TWO=bar"}, 24 }, 25 { 26 description: "Merging two variables with same key", 27 first: []string{"VAR_ONE=foo"}, 28 second: []string{"VAR_ONE=bar"}, 29 expectedResult: []string{"VAR_ONE=bar"}, 30 }, 31 { 32 description: "With same variable in list", 33 first: []string{"VAR_ONE=foo", "VAR_TWO=xyz"}, 34 second: []string{"VAR_ONE=bar", "HOME=/home/user"}, 35 expectedResult: []string{"VAR_TWO=xyz", "VAR_ONE=bar", "HOME=/home/user"}, 36 }, 37 } 38 39 for _, tc := range tests { 40 t.Log(tc.description) 41 sort.Strings(tc.expectedResult) 42 result := Merge(tc.first, tc.second) 43 sort.Strings(result) 44 assert.Equal(t, tc.expectedResult, result) 45 } 46 }