Add an HTTP Last-Modified header testcase
| ... | ... |
@@ -668,6 +668,73 @@ func TestBuildCacheADD(t *testing.T) {
|
| 668 | 668 |
logDone("build - build two images with remote ADD")
|
| 669 | 669 |
} |
| 670 | 670 |
|
| 671 |
+func TestBuildLastModified(t *testing.T) {
|
|
| 672 |
+ name := "testbuildlastmodified" |
|
| 673 |
+ defer deleteImages(name) |
|
| 674 |
+ |
|
| 675 |
+ server, err := fakeStorage(map[string]string{
|
|
| 676 |
+ "file": "hello", |
|
| 677 |
+ }) |
|
| 678 |
+ if err != nil {
|
|
| 679 |
+ t.Fatal(err) |
|
| 680 |
+ } |
|
| 681 |
+ defer server.Close() |
|
| 682 |
+ |
|
| 683 |
+ var out, out2 string |
|
| 684 |
+ |
|
| 685 |
+ dFmt := `FROM busybox |
|
| 686 |
+ADD %s/file / |
|
| 687 |
+RUN ls -le /file` |
|
| 688 |
+ |
|
| 689 |
+ dockerfile := fmt.Sprintf(dFmt, server.URL) |
|
| 690 |
+ |
|
| 691 |
+ if _, out, err = buildImageWithOut(name, dockerfile, false); err != nil {
|
|
| 692 |
+ t.Fatal(err) |
|
| 693 |
+ } |
|
| 694 |
+ |
|
| 695 |
+ originMTime := regexp.MustCompile(`root.*/file.*\n`).FindString(out) |
|
| 696 |
+ // Make sure our regexp is correct |
|
| 697 |
+ if strings.Index(originMTime, "/file") < 0 {
|
|
| 698 |
+ t.Fatalf("Missing ls info on 'file':\n%s", out)
|
|
| 699 |
+ } |
|
| 700 |
+ |
|
| 701 |
+ // Build it again and make sure the mtime of the file didn't change. |
|
| 702 |
+ // Wait a few seconds to make sure the time changed enough to notice |
|
| 703 |
+ time.Sleep(2 * time.Second) |
|
| 704 |
+ |
|
| 705 |
+ if _, out2, err = buildImageWithOut(name, dockerfile, false); err != nil {
|
|
| 706 |
+ t.Fatal(err) |
|
| 707 |
+ } |
|
| 708 |
+ |
|
| 709 |
+ newMTime := regexp.MustCompile(`root.*/file.*\n`).FindString(out2) |
|
| 710 |
+ if newMTime != originMTime {
|
|
| 711 |
+ t.Fatalf("MTime changed:\nOrigin:%s\nNew:%s", originMTime, newMTime)
|
|
| 712 |
+ } |
|
| 713 |
+ |
|
| 714 |
+ // Now 'touch' the file and make sure the timestamp DID change this time |
|
| 715 |
+ // Create a new fakeStorage instead of just using Add() to help windows |
|
| 716 |
+ server, err = fakeStorage(map[string]string{
|
|
| 717 |
+ "file": "hello", |
|
| 718 |
+ }) |
|
| 719 |
+ if err != nil {
|
|
| 720 |
+ t.Fatal(err) |
|
| 721 |
+ } |
|
| 722 |
+ defer server.Close() |
|
| 723 |
+ |
|
| 724 |
+ dockerfile = fmt.Sprintf(dFmt, server.URL) |
|
| 725 |
+ |
|
| 726 |
+ if _, out2, err = buildImageWithOut(name, dockerfile, false); err != nil {
|
|
| 727 |
+ t.Fatal(err) |
|
| 728 |
+ } |
|
| 729 |
+ |
|
| 730 |
+ newMTime = regexp.MustCompile(`root.*/file.*\n`).FindString(out2) |
|
| 731 |
+ if newMTime == originMTime {
|
|
| 732 |
+ t.Fatalf("MTime didn't change:\nOrigin:%s\nNew:%s", originMTime, newMTime)
|
|
| 733 |
+ } |
|
| 734 |
+ |
|
| 735 |
+ logDone("build - use Last-Modified header")
|
|
| 736 |
+} |
|
| 737 |
+ |
|
| 671 | 738 |
func TestBuildSixtySteps(t *testing.T) {
|
| 672 | 739 |
name := "foobuildsixtysteps" |
| 673 | 740 |
defer deleteImages(name) |