@@ -85,7 +85,7 @@ func TestApplyLayers(t *testing.T) {
85
85
Version : "1.2.3" ,
86
86
Release : "4.5.6" ,
87
87
},
88
- {
88
+ { // added
89
89
Name : "musl" ,
90
90
Version : "1.2.4" ,
91
91
Release : "4.5.7" ,
@@ -95,6 +95,27 @@ func TestApplyLayers(t *testing.T) {
95
95
},
96
96
WhiteoutFiles : []string {"app/composer.lock" },
97
97
},
98
+ {
99
+ SchemaVersion : 1 ,
100
+ ID : "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" ,
101
+ PackageInfos : []types.PackageInfo {
102
+ {
103
+ FilePath : "lib/apk/db/installed" ,
104
+ Packages : []types.Package {
105
+ {
106
+ Name : "openssl" ,
107
+ Version : "1.2.3" ,
108
+ Release : "4.5.6" ,
109
+ },
110
+ {
111
+ Name : "musl" ,
112
+ Version : "1.2.4" ,
113
+ Release : "4.5.8" , // updated
114
+ },
115
+ },
116
+ },
117
+ },
118
+ },
98
119
},
99
120
expectedImageDetail : types.ImageDetail {
100
121
OS : & types.OS {
@@ -105,14 +126,14 @@ func TestApplyLayers(t *testing.T) {
105
126
{
106
127
Name : "musl" ,
107
128
Version : "1.2.4" ,
108
- Release : "4.5.7 " ,
109
- LayerID : "sha256:24df0d4e20c0f42d3703bf1f1db2bdd77346c7956f74f423603d651e8e5ae8a7 " ,
129
+ Release : "4.5.8 " ,
130
+ LayerID : "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4 " ,
110
131
},
111
132
{
112
133
Name : "openssl" ,
113
134
Version : "1.2.3" ,
114
135
Release : "4.5.6" ,
115
- LayerID : "sha256:24df0d4e20c0f42d3703bf1f1db2bdd77346c7956f74f423603d651e8e5ae8a7 " ,
136
+ LayerID : "sha256:932da51564135c98a49a34a193d6cd363d8fa4184d957fde16c9d8527b3f3b02 " ,
116
137
},
117
138
},
118
139
Applications : []types.Application {
@@ -132,6 +153,129 @@ func TestApplyLayers(t *testing.T) {
132
153
},
133
154
},
134
155
},
156
+ {
157
+ name : "happy path with removed and updated lockfile" ,
158
+ inputLayers : []types.LayerInfo {
159
+ {
160
+ SchemaVersion : 1 ,
161
+ ID : "sha256:932da51564135c98a49a34a193d6cd363d8fa4184d957fde16c9d8527b3f3b02" ,
162
+ OS : & types.OS {
163
+ Family : "alpine" ,
164
+ Name : "3.10" ,
165
+ },
166
+ Applications : []types.Application {
167
+ {
168
+ Type : "gem" ,
169
+ FilePath : "app/Gemfile.lock" ,
170
+ Libraries : []types.LibraryInfo {
171
+ {
172
+ Library : godeptypes.Library {
173
+ Name : "rails" ,
174
+ Version : "5.0.0" ,
175
+ },
176
+ },
177
+ {
178
+ Library : godeptypes.Library {
179
+ Name : "rack" ,
180
+ Version : "4.0.0" ,
181
+ },
182
+ },
183
+ },
184
+ },
185
+ {
186
+ Type : "composer" ,
187
+ FilePath : "app/composer.lock" ,
188
+ Libraries : []types.LibraryInfo {
189
+ {
190
+ Library : godeptypes.Library {
191
+ Name : "phplibrary1" ,
192
+ Version : "6.6.6" ,
193
+ },
194
+ },
195
+ },
196
+ },
197
+ },
198
+ },
199
+ {
200
+ SchemaVersion : 1 ,
201
+ ID : "sha256:24df0d4e20c0f42d3703bf1f1db2bdd77346c7956f74f423603d651e8e5ae8a7" ,
202
+ Applications : []types.Application {
203
+ {
204
+ Type : "gem" ,
205
+ FilePath : "app/Gemfile.lock" ,
206
+ Libraries : []types.LibraryInfo {
207
+ {
208
+ Library : godeptypes.Library {
209
+ Name : "rails" ,
210
+ Version : "6.0.0" ,
211
+ },
212
+ },
213
+ {
214
+ Library : godeptypes.Library {
215
+ Name : "rack" ,
216
+ Version : "4.0.0" ,
217
+ },
218
+ },
219
+ },
220
+ },
221
+ {
222
+ Type : "composer" ,
223
+ FilePath : "app/composer2.lock" ,
224
+ Libraries : []types.LibraryInfo {
225
+ {
226
+ Library : godeptypes.Library {
227
+ Name : "phplibrary1" ,
228
+ Version : "6.6.6" ,
229
+ },
230
+ },
231
+ },
232
+ },
233
+ },
234
+ WhiteoutFiles : []string {"app/composer.lock" },
235
+ },
236
+ },
237
+ expectedImageDetail : types.ImageDetail {
238
+ OS : & types.OS {
239
+ Family : "alpine" ,
240
+ Name : "3.10" ,
241
+ },
242
+ Applications : []types.Application {
243
+ {
244
+ Type : "gem" ,
245
+ FilePath : "app/Gemfile.lock" ,
246
+ Libraries : []types.LibraryInfo {
247
+ {
248
+ Library : godeptypes.Library {
249
+ Name : "rack" ,
250
+ Version : "4.0.0" ,
251
+ },
252
+ LayerID : "sha256:932da51564135c98a49a34a193d6cd363d8fa4184d957fde16c9d8527b3f3b02" ,
253
+ },
254
+ {
255
+ Library : godeptypes.Library {
256
+ Name : "rails" ,
257
+ Version : "6.0.0" ,
258
+ },
259
+ LayerID : "sha256:24df0d4e20c0f42d3703bf1f1db2bdd77346c7956f74f423603d651e8e5ae8a7" ,
260
+ },
261
+ },
262
+ },
263
+ {
264
+ Type : "composer" ,
265
+ FilePath : "app/composer2.lock" ,
266
+ Libraries : []types.LibraryInfo {
267
+ {
268
+ Library : godeptypes.Library {
269
+ Name : "phplibrary1" ,
270
+ Version : "6.6.6" ,
271
+ },
272
+ LayerID : "sha256:24df0d4e20c0f42d3703bf1f1db2bdd77346c7956f74f423603d651e8e5ae8a7" ,
273
+ },
274
+ },
275
+ },
276
+ },
277
+ },
278
+ },
135
279
{
136
280
name : "happy path with status.d" ,
137
281
inputLayers : []types.LayerInfo {
@@ -211,11 +355,21 @@ func TestApplyLayers(t *testing.T) {
211
355
}
212
356
213
357
for _ , tc := range testCases {
214
- gotImageDetail := ApplyLayers (tc .inputLayers )
215
- sort .Slice (gotImageDetail .Packages , func (i , j int ) bool {
216
- return gotImageDetail .Packages [i ].Name < gotImageDetail .Packages [j ].Name
358
+ t .Run (tc .name , func (t * testing.T ) {
359
+ gotImageDetail := ApplyLayers (tc .inputLayers )
360
+ sort .Slice (gotImageDetail .Packages , func (i , j int ) bool {
361
+ return gotImageDetail .Packages [i ].Name < gotImageDetail .Packages [j ].Name
362
+ })
363
+ sort .Slice (gotImageDetail .Applications , func (i , j int ) bool {
364
+ return gotImageDetail .Applications [i ].FilePath < gotImageDetail .Applications [j ].FilePath
365
+ })
366
+ for _ , app := range gotImageDetail .Applications {
367
+ sort .Slice (app .Libraries , func (i , j int ) bool {
368
+ return app .Libraries [i ].Library .Name < app .Libraries [j ].Library .Name
369
+ })
370
+ }
371
+ assert .Equal (t , tc .expectedImageDetail , gotImageDetail , tc .name )
217
372
})
218
- assert .Equal (t , tc .expectedImageDetail , gotImageDetail , tc .name )
219
373
}
220
374
}
221
375
0 commit comments