@@ -20,6 +20,7 @@ import (
20
20
"archive/tar"
21
21
"bytes"
22
22
"fmt"
23
+ "os"
23
24
"path/filepath"
24
25
"reflect"
25
26
"sort"
@@ -948,6 +949,7 @@ func Test_stageBuilder_build(t *testing.T) {
948
949
crossStageDeps map [int ][]string
949
950
mockGetFSFromImage func (root string , img v1.Image , extract util.ExtractFunction ) ([]string , error )
950
951
shouldInitSnapshot bool
952
+ skipReason string
951
953
}
952
954
953
955
testCases := []testcase {
@@ -1136,6 +1138,13 @@ func Test_stageBuilder_build(t *testing.T) {
1136
1138
}
1137
1139
}(),
1138
1140
func () testcase {
1141
+ name := "copy command cache enabled and key is not in cache"
1142
+ if os .Getuid () != 0 {
1143
+ return testcase {
1144
+ description : name ,
1145
+ skipReason : "test requires root, attempts chown" ,
1146
+ }
1147
+ }
1139
1148
dir , filenames := tempDirAndFile (t )
1140
1149
filename := filenames [0 ]
1141
1150
tarContent := []byte {}
@@ -1174,7 +1183,7 @@ COPY %s foo.txt
1174
1183
1175
1184
cmds := stage .Commands
1176
1185
return testcase {
1177
- description : "copy command cache enabled and key is not in cache" ,
1186
+ description : name ,
1178
1187
opts : opts ,
1179
1188
config : & v1.ConfigFile {Config : v1.Config {WorkingDir : destDir }},
1180
1189
layerCache : & fakeLayerCache {},
@@ -1193,6 +1202,13 @@ COPY %s foo.txt
1193
1202
}
1194
1203
}(),
1195
1204
func () testcase {
1205
+ name := "cached run command followed by uncached copy command results in consistent read and write hashes"
1206
+ if os .Getuid () != 0 {
1207
+ return testcase {
1208
+ description : name ,
1209
+ skipReason : "test requires root, attempts chown" ,
1210
+ }
1211
+ }
1196
1212
dir , filenames := tempDirAndFile (t )
1197
1213
filename := filenames [0 ]
1198
1214
tarContent := generateTar (t , filename )
@@ -1251,7 +1267,7 @@ COPY %s bar.txt
1251
1267
1252
1268
cmds := stage .Commands
1253
1269
return testcase {
1254
- description : "cached run command followed by uncached copy command results in consistent read and write hashes" ,
1270
+ description : name ,
1255
1271
opts : & config.KanikoOptions {Cache : true , CacheCopyLayers : true , CacheRunLayers : true },
1256
1272
rootDir : dir ,
1257
1273
config : & v1.ConfigFile {Config : v1.Config {WorkingDir : destDir }},
@@ -1267,6 +1283,14 @@ COPY %s bar.txt
1267
1283
}
1268
1284
}(),
1269
1285
func () testcase {
1286
+ name := "copy command followed by cached run command results in consistent read and write hashes"
1287
+ if os .Getuid () != 0 {
1288
+ return testcase {
1289
+ description : name ,
1290
+ skipReason : "test requires root, attempts chown" ,
1291
+ }
1292
+ }
1293
+
1270
1294
dir , filenames := tempDirAndFile (t )
1271
1295
filename := filenames [0 ]
1272
1296
tarContent := generateTar (t , filename )
@@ -1325,7 +1349,7 @@ RUN foobar
1325
1349
1326
1350
cmds := stage .Commands
1327
1351
return testcase {
1328
- description : "copy command followed by cached run command results in consistent read and write hashes" ,
1352
+ description : name ,
1329
1353
opts : & config.KanikoOptions {Cache : true , CacheRunLayers : true },
1330
1354
rootDir : dir ,
1331
1355
config : & v1.ConfigFile {Config : v1.Config {WorkingDir : destDir }},
@@ -1471,6 +1495,9 @@ RUN foobar
1471
1495
}
1472
1496
for _ , tc := range testCases {
1473
1497
t .Run (tc .description , func (t * testing.T ) {
1498
+ if tc .skipReason != "" {
1499
+ t .Skip (tc .skipReason )
1500
+ }
1474
1501
var fileName string
1475
1502
if tc .commands == nil {
1476
1503
file , err := filesystem .CreateTemp ("" , "foo" )
0 commit comments