@@ -23,6 +23,7 @@ package dazzle
23
23
import (
24
24
"testing"
25
25
26
+ "github.com/google/go-cmp/cmp"
26
27
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
27
28
)
28
29
@@ -39,29 +40,29 @@ func TestMergeEnv(t *testing.T) {
39
40
base : & ociv1.Image {
40
41
Config : ociv1.ImageConfig {
41
42
Env : []string {
42
- "PATH=first:second:third:$PATH " ,
43
+ "PATH=first:second:third:common-value " ,
43
44
},
44
45
},
45
46
},
46
47
others : []* ociv1.Image {
47
48
{
48
49
Config : ociv1.ImageConfig {
49
50
Env : []string {
50
- "PATH=fourth:fifth:$PATH " ,
51
+ "PATH=fourth:fifth:common-value " ,
51
52
},
52
53
},
53
54
},
54
55
{
55
56
Config : ociv1.ImageConfig {
56
57
Env : []string {
57
- "PATH=sixth:sixth:$PATH " ,
58
+ "PATH=sixth:sixth:common-value " ,
58
59
},
59
60
},
60
61
},
61
62
{
62
63
Config : ociv1.ImageConfig {
63
64
Env : []string {
64
- "PATH=eighth: seventh:eighth:$PATH " ,
65
+ "PATH=seventh:eighth:seventh:common-value " ,
65
66
},
66
67
},
67
68
},
@@ -72,36 +73,36 @@ func TestMergeEnv(t *testing.T) {
72
73
Action : EnvVarCombineMergeUnique ,
73
74
},
74
75
},
75
- expect : []string {"PATH=first:second:third:fourth:fifth:sixth:seventh:eighth:$PATH " },
76
+ expect : []string {"PATH=first:second:third:common-value: fourth:fifth:sixth:seventh:eighth" },
76
77
},
77
78
{
78
79
name : "EnvVarCombineMerge" ,
79
80
base : & ociv1.Image {
80
81
Config : ociv1.ImageConfig {
81
82
Env : []string {
82
- "PATH=first:second:third:$PATH " ,
83
+ "PATH=first:second:third:common-value " ,
83
84
},
84
85
},
85
86
},
86
87
others : []* ociv1.Image {
87
88
{
88
89
Config : ociv1.ImageConfig {
89
90
Env : []string {
90
- "PATH=fourth:fifth:$PATH " ,
91
+ "PATH=fourth:fifth:common-value " ,
91
92
},
92
93
},
93
94
},
94
95
{
95
96
Config : ociv1.ImageConfig {
96
97
Env : []string {
97
- "PATH=sixth:sixth:$PATH " ,
98
+ "PATH=sixth:sixth:common-value " ,
98
99
},
99
100
},
100
101
},
101
102
{
102
103
Config : ociv1.ImageConfig {
103
104
Env : []string {
104
- "PATH=eighth:seventh:eighth:$PATH " ,
105
+ "PATH=eighth:seventh:eighth:common-value " ,
105
106
},
106
107
},
107
108
},
@@ -112,22 +113,22 @@ func TestMergeEnv(t *testing.T) {
112
113
Action : EnvVarCombineMerge ,
113
114
},
114
115
},
115
- expect : []string {"PATH=first:second:third:$PATH :fourth:fifth:$PATH :sixth:sixth:$PATH :eighth:seventh:eighth:$PATH " },
116
+ expect : []string {"PATH=first:second:third:common-value :fourth:fifth:common-value :sixth:sixth:common-value :eighth:seventh:eighth:common-value " },
116
117
},
117
118
{
118
119
name : "EnvVarCombineUseLast" ,
119
120
base : & ociv1.Image {
120
121
Config : ociv1.ImageConfig {
121
122
Env : []string {
122
- "PATH=first:second:third:$PATH " ,
123
+ "PATH=first:second:third:common-value " ,
123
124
},
124
125
},
125
126
},
126
127
others : []* ociv1.Image {
127
128
{
128
129
Config : ociv1.ImageConfig {
129
130
Env : []string {
130
- "PATH=fourth:fifth:$PATH " ,
131
+ "PATH=fourth:fifth:common-value " ,
131
132
},
132
133
},
133
134
},
@@ -138,22 +139,22 @@ func TestMergeEnv(t *testing.T) {
138
139
Action : EnvVarCombineUseLast ,
139
140
},
140
141
},
141
- expect : []string {"PATH=fourth:fifth:$PATH " },
142
+ expect : []string {"PATH=fourth:fifth:common-value " },
142
143
},
143
144
{
144
145
name : "EnvVarCombineUseFirst" ,
145
146
base : & ociv1.Image {
146
147
Config : ociv1.ImageConfig {
147
148
Env : []string {
148
- "PATH=first:second:third:$PATH " ,
149
+ "PATH=first:second:third:common-value " ,
149
150
},
150
151
},
151
152
},
152
153
others : []* ociv1.Image {
153
154
{
154
155
Config : ociv1.ImageConfig {
155
156
Env : []string {
156
- "PATH=fourth:fifth:$PATH " ,
157
+ "PATH=fourth:fifth:common-value " ,
157
158
},
158
159
},
159
160
},
@@ -164,22 +165,18 @@ func TestMergeEnv(t *testing.T) {
164
165
Action : EnvVarCombineUseFirst ,
165
166
},
166
167
},
167
- expect : []string {"PATH=first:second:third:$PATH " },
168
+ expect : []string {"PATH=first:second:third:common-value " },
168
169
},
169
170
}
170
171
for _ , test := range tests {
171
- envs , err := mergeEnv (test .base , test .others , test .vars )
172
- if err != nil {
173
- t .Fatal (err )
174
- }
175
- if len (envs ) != len (test .expect ) {
176
- t .Fatal ("unexpected length" , len (envs ))
177
- }
178
- for i , env := range envs {
179
- if env != test .expect [i ] {
180
- t .Fatal ("unexpected env" , envs )
172
+ t .Run (test .name , func (t * testing.T ) {
173
+ envs , err := mergeEnv (test .base , test .others , test .vars )
174
+ if err != nil {
175
+ t .Fatal (err )
181
176
}
182
-
183
- }
177
+ if diff := cmp .Diff (envs , test .expect ); len (diff ) != 0 {
178
+ t .Errorf ("mergeEnv() mismatch (-want +got):\n %s" , diff )
179
+ }
180
+ })
184
181
}
185
182
}
0 commit comments