github.com/cilki/sh@v2.6.4+incompatible/expand/environ_test.go (about) 1 // Copyright (c) 2018, Daniel Martà <mvdan@mvdan.cc> 2 // See LICENSE for licensing information 3 4 package expand 5 6 import ( 7 "reflect" 8 "testing" 9 ) 10 11 func TestListEnviron(t *testing.T) { 12 tests := []struct { 13 name string 14 upper bool 15 pairs []string 16 want []string 17 }{ 18 { 19 name: "Empty", 20 pairs: nil, 21 want: []string{}, 22 }, 23 { 24 name: "Simple", 25 pairs: []string{"A=b", "c="}, 26 want: []string{"A=b", "c="}, 27 }, 28 { 29 name: "MissingEqual", 30 pairs: []string{"A=b", "invalid", "c="}, 31 want: []string{"A=b", "c="}, 32 }, 33 { 34 name: "DuplicateNames", 35 pairs: []string{"A=b", "A=x", "c=", "c=y"}, 36 want: []string{"A=x", "c=y"}, 37 }, 38 { 39 name: "NoName", 40 pairs: []string{"=b", "=c"}, 41 want: []string{}, 42 }, 43 { 44 name: "EmptyElements", 45 pairs: []string{"A=b", "", "", "c="}, 46 want: []string{"A=b", "c="}, 47 }, 48 { 49 name: "MixedCaseNoUpper", 50 pairs: []string{"A=b1", "Path=foo", "a=b2"}, 51 want: []string{"A=b1", "Path=foo", "a=b2"}, 52 }, 53 { 54 name: "MixedCaseUpper", 55 upper: true, 56 pairs: []string{"A=b1", "Path=foo", "a=b2"}, 57 want: []string{"A=b2", "PATH=foo"}, 58 }, 59 } 60 for _, tc := range tests { 61 t.Run(tc.name, func(t *testing.T) { 62 gotEnv := listEnvironWithUpper(tc.upper, tc.pairs...) 63 got := []string(gotEnv.(listEnviron)) 64 if !reflect.DeepEqual(got, tc.want) { 65 t.Fatalf("ListEnviron(%t, %q) wanted %q, got %q", 66 tc.upper, tc.pairs, tc.want, got) 67 } 68 }) 69 } 70 }