@@ -8,44 +8,52 @@ import (
8
8
"testing"
9
9
)
10
10
11
- func TestAllowedOnly (t * testing.T ) {
11
+ func TestPartitionByAllowlist (t * testing.T ) {
12
12
tests := []struct {
13
- name string
14
- envVars map [string ]string
15
- allowed []string
16
- expected []string
13
+ name string
14
+ envVars map [string ]string
15
+ allowList []string
16
+ expectedInclude []string
17
+ expectedExclude []string
17
18
}{
18
19
{
19
- name : "returns only allowed env vars" ,
20
+ name : "partitions env vars correctly " ,
20
21
envVars : map [string ]string {
21
22
"ALLOWED1" : "value1" ,
22
23
"ALLOWED2" : "value2" ,
23
24
"NOT_ALLOWED1" : "value3" ,
24
25
"NOT_ALLOWED2" : "value4" ,
25
26
},
26
- allowed : []string {"ALLOWED1" , "ALLOWED2" },
27
- expected : []string {
27
+ allowList : []string {"ALLOWED1" , "ALLOWED2" },
28
+ expectedInclude : []string {
28
29
"ALLOWED1=value1" ,
29
30
"ALLOWED2=value2" ,
30
31
},
32
+ expectedExclude : []string {
33
+ "NOT_ALLOWED1=value3" ,
34
+ "NOT_ALLOWED2=value4" ,
35
+ },
31
36
},
32
37
{
33
- name : "returns empty slice when no env vars match allowlist" ,
34
- envVars : map [string ]string {"FOO" : "bar" },
35
- allowed : []string {"BAZ" },
36
- expected : nil ,
38
+ name : "returns empty slices when no env vars match allowlist" ,
39
+ envVars : map [string ]string {"FOO" : "bar" },
40
+ allowList : []string {"BAZ" },
41
+ expectedInclude : nil ,
42
+ expectedExclude : []string {"FOO=bar" },
37
43
},
38
44
{
39
- name : "returns empty slice when allowlist is empty" ,
40
- envVars : map [string ]string {"FOO" : "bar" },
41
- allowed : []string {},
42
- expected : nil ,
45
+ name : "returns empty included and all in excluded when allowlist is empty" ,
46
+ envVars : map [string ]string {"FOO" : "bar" },
47
+ allowList : []string {},
48
+ expectedInclude : nil ,
49
+ expectedExclude : []string {"FOO=bar" },
43
50
},
44
51
{
45
- name : "returns empty slice when env vars is empty" ,
46
- envVars : map [string ]string {},
47
- allowed : []string {"FOO" },
48
- expected : nil ,
52
+ name : "returns empty slices when env vars is empty" ,
53
+ envVars : map [string ]string {},
54
+ allowList : []string {"FOO" },
55
+ expectedInclude : nil ,
56
+ expectedExclude : nil ,
49
57
},
50
58
}
51
59
@@ -56,14 +64,18 @@ func TestAllowedOnly(t *testing.T) {
56
64
os .Setenv (k , v )
57
65
}
58
66
59
- got := allowedOnly (tt .allowed )
67
+ included , excluded := partitionByAllowlist (tt .allowList )
60
68
61
- if tt .expected == nil && len (got ) == 0 {
62
- return
69
+ if tt .expectedInclude == nil && len (included ) == 0 {
70
+ // ok
71
+ } else if ! reflect .DeepEqual (included , tt .expectedInclude ) {
72
+ t .Errorf ("partitionByAllowlist() included = %v, want %v" , included , tt .expectedInclude )
63
73
}
64
74
65
- if ! reflect .DeepEqual (got , tt .expected ) {
66
- t .Errorf ("AllowedOnly() = %v, want %v" , got , tt .expected )
75
+ if tt .expectedExclude == nil && len (excluded ) == 0 {
76
+ // ok
77
+ } else if ! reflect .DeepEqual (excluded , tt .expectedExclude ) {
78
+ t .Errorf ("partitionByAllowlist() excluded = %v, want %v" , excluded , tt .expectedExclude )
67
79
}
68
80
})
69
81
}
@@ -94,7 +106,7 @@ func TestKeys(t *testing.T) {
94
106
95
107
for _ , tt := range tests {
96
108
t .Run (tt .name , func (t * testing.T ) {
97
- got := Keys (tt .input )
109
+ got := keys (tt .input )
98
110
if ! reflect .DeepEqual (got , tt .expected ) {
99
111
t .Errorf ("Keys() = %v, want %v" , got , tt .expected )
100
112
}
0 commit comments