This new version makes sure that the same context is used for the two
builds run in the test. If you don't use the same build then about 1/2 the
time the file copied into the container will look like a different file,
probably due to timestamp differences. But reusing the same context we
re-use the same file on disk and therefore avoid the change in timestamps,
and we use the cache on the 2nd build.
Signed-off-by: Doug Davis <dug@us.ibm.com>
... | ... |
@@ -296,17 +296,8 @@ func TestBuildCopyWildcardNoFind(t *testing.T) { |
296 | 296 |
func TestBuildCopyWildcardCache(t *testing.T) { |
297 | 297 |
name := "testcopywildcardcache" |
298 | 298 |
defer deleteImages(name) |
299 |
- server, err := fakeStorage(map[string]string{ |
|
300 |
- "robots.txt": "hello", |
|
301 |
- "index.html": "world", |
|
302 |
- }) |
|
303 |
- if err != nil { |
|
304 |
- t.Fatal(err) |
|
305 |
- } |
|
306 |
- defer server.Close() |
|
307 | 299 |
ctx, err := fakeContext(`FROM busybox |
308 |
- COPY file1.txt /tmp/ |
|
309 |
- `, |
|
300 |
+ COPY file1.txt /tmp/`, |
|
310 | 301 |
map[string]string{ |
311 | 302 |
"file1.txt": "test1", |
312 | 303 |
}) |
... | ... |
@@ -315,30 +306,17 @@ func TestBuildCopyWildcardCache(t *testing.T) { |
315 | 315 |
t.Fatal(err) |
316 | 316 |
} |
317 | 317 |
|
318 |
- if err != nil { |
|
319 |
- t.Fatal(err) |
|
320 |
- } |
|
321 | 318 |
id1, err := buildImageFromContext(name, ctx, true) |
322 | 319 |
if err != nil { |
323 | 320 |
t.Fatal(err) |
324 | 321 |
} |
325 | 322 |
|
326 |
- // Now make sure we use a cache the 2nd time even with wild card |
|
327 |
- ctx2, err := fakeContext(`FROM busybox |
|
328 |
- COPY file*.txt /tmp/ |
|
329 |
- `, |
|
330 |
- map[string]string{ |
|
331 |
- "file1.txt": "test1", |
|
332 |
- }) |
|
333 |
- defer ctx2.Close() |
|
334 |
- if err != nil { |
|
335 |
- t.Fatal(err) |
|
336 |
- } |
|
323 |
+ // Now make sure we use a cache the 2nd time even with wild cards. |
|
324 |
+ // Use the same context so the file is the same and the checksum will match |
|
325 |
+ ctx.Add("Dockerfile", `FROM busybox |
|
326 |
+ COPY file*.txt /tmp/`) |
|
337 | 327 |
|
338 |
- if err != nil { |
|
339 |
- t.Fatal(err) |
|
340 |
- } |
|
341 |
- id2, err := buildImageFromContext(name, ctx2, true) |
|
328 |
+ id2, err := buildImageFromContext(name, ctx, true) |
|
342 | 329 |
if err != nil { |
343 | 330 |
t.Fatal(err) |
344 | 331 |
} |