Source file
src/os/exec/env_test.go
1
2
3
4
5 package exec
6
7 import (
8 "slices"
9 "testing"
10 )
11
12 func TestDedupEnv(t *testing.T) {
13 t.Parallel()
14
15 tests := []struct {
16 noCase bool
17 nulOK bool
18 in []string
19 want []string
20 wantErr bool
21 }{
22 {
23 noCase: true,
24 in: []string{"k1=v1", "k2=v2", "K1=v3"},
25 want: []string{"k2=v2", "K1=v3"},
26 },
27 {
28 noCase: false,
29 in: []string{"k1=v1", "K1=V2", "k1=v3"},
30 want: []string{"K1=V2", "k1=v3"},
31 },
32 {
33 in: []string{"=a", "=b", "foo", "bar"},
34 want: []string{"=b", "foo", "bar"},
35 },
36 {
37
38 noCase: true,
39 in: []string{`=C:=C:\golang`, `=D:=D:\tmp`, `=D:=D:\`},
40 want: []string{`=C:=C:\golang`, `=D:=D:\`},
41 },
42 {
43
44
45 in: []string{"dodgy", "entries"},
46 want: []string{"dodgy", "entries"},
47 },
48 {
49
50 in: []string{"A=a\x00b", "B=b", "C\x00C=c"},
51 want: []string{"B=b"},
52 wantErr: true,
53 },
54 {
55
56 nulOK: true,
57 in: []string{"path=one\x00two"},
58 want: []string{"path=one\x00two"},
59 },
60 }
61 for _, tt := range tests {
62 got, err := dedupEnvCase(tt.noCase, tt.nulOK, tt.in)
63 if !slices.Equal(got, tt.want) || (err != nil) != tt.wantErr {
64 t.Errorf("Dedup(%v, %q) = %q, %v; want %q, error:%v", tt.noCase, tt.in, got, err, tt.want, tt.wantErr)
65 }
66 }
67 }
68
View as plain text