From 3c94bf814e45dc02b2c53f2ca74b426d9442e0f8 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 17 Feb 2017 13:58:48 -0800 Subject: [PATCH] Add deletion test Test deleting multiple files, directories, and creating the equivalent of an opaque directory. Signed-off-by: Derek McGowan (github: dmcgowan) --- archive/tar_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/archive/tar_test.go b/archive/tar_test.go index 9ec960e..1245baa 100644 --- a/archive/tar_test.go +++ b/archive/tar_test.go @@ -78,6 +78,37 @@ func TestDiffApply(t *testing.T) { } } +// TestDiffApplyDeletion checks various deletion scenarios to ensure +// deletions are properly picked up and applied +func TestDiffApplyDeletion(t *testing.T) { + as := []fstest.Applier{ + fstest.Apply( + fstest.CreateDir("/test/somedir", 0755), + fstest.CreateDir("/lib", 0700), + fstest.CreateFile("/lib/hidden", []byte{}, 0644), + ), + fstest.Apply( + fstest.CreateFile("/test/a", []byte{}, 0644), + fstest.CreateFile("/test/b", []byte{}, 0644), + fstest.CreateDir("/test/otherdir", 0755), + fstest.CreateFile("/test/otherdir/.empty", []byte{}, 0644), + fstest.RemoveFile("/lib"), + fstest.CreateDir("/lib", 0700), + fstest.CreateFile("/lib/not-hidden", []byte{}, 0644), + ), + fstest.Apply( + fstest.RemoveFile("/test/a"), + fstest.RemoveFile("/test/b"), + fstest.RemoveFile("/test/otherdir"), + fstest.CreateFile("/lib/newfile", []byte{}, 0644), + ), + } + + if err := testDiffApply(as...); err != nil { + t.Fatalf("Test diff apply failed: %+v", err) + } +} + func testApply(a fstest.Applier) error { td, err := ioutil.TempDir("", "test-apply-") if err != nil {