@@ -212,18 +212,21 @@ func TestUnpackEntryParentDir(t *testing.T) {
212212// as well as ensuring that the metadata of the parent is maintained.
213213func TestUnpackEntryWhiteout (t * testing.T ) {
214214 for _ , test := range []struct {
215- name string
216- path string
217- dir bool // TODO: Switch to Typeflag
215+ name string
216+ path string
217+ dir bool // TODO: Switch to Typeflag
218+ expectedErr error
218219 }{
219- {"FileInRoot" , "rootpath" , false },
220- {"HiddenFileInRoot" , ".hiddenroot" , false },
221- {"FileInSubdir" , "some/path/file" , false },
222- {"HiddenFileInSubdir" , "another/path/.hiddenfile" , false },
223- {"DirInRoot" , "rootpath" , true },
224- {"HiddenDirInRoot" , ".hiddenroot" , true },
225- {"DirInSubdir" , "some/path/dir" , true },
226- {"HiddenDirInSubdir" , "another/path/.hiddendir" , true },
220+ {"EmptyWhiteoutName-Root" , "" , false , errInvalidWhiteout },
221+ {"EmptyWhiteoutName" , "some/path/" , false , errInvalidWhiteout },
222+ {"FileInRoot" , "rootpath" , false , nil },
223+ {"HiddenFileInRoot" , ".hiddenroot" , false , nil },
224+ {"FileInSubdir" , "some/path/file" , false , nil },
225+ {"HiddenFileInSubdir" , "another/path/.hiddenfile" , false , nil },
226+ {"DirInRoot" , "rootpath" , true , nil },
227+ {"HiddenDirInRoot" , ".hiddenroot" , true , nil },
228+ {"DirInSubdir" , "some/path/dir" , true , nil },
229+ {"HiddenDirInSubdir" , "another/path/.hiddendir" , true , nil },
227230 } {
228231 t .Run (test .name , func (t * testing.T ) {
229232 testMtime := testhelpers .Unix (123 , 456 )
@@ -255,7 +258,7 @@ func TestUnpackEntryWhiteout(t *testing.T) {
255258
256259 err = os .WriteFile (filepath .Join (dir , test .path , ".subdir" , "file3" ), []byte ("some value" ), 0o644 )
257260 require .NoError (t , err )
258- } else {
261+ } else if rawFile != "" {
259262 err := os .WriteFile (filepath .Join (dir , test .path ), []byte ("some value" ), 0o644 )
260263 require .NoError (t , err )
261264 }
@@ -272,11 +275,14 @@ func TestUnpackEntryWhiteout(t *testing.T) {
272275
273276 te := NewTarExtractor (nil )
274277 err = te .UnpackEntry (dir , hdr , nil )
275- require .NoErrorf (t , err , "UnpackEntry %s whiteout" , hdr .Name )
276-
277- // Make sure that the path is gone.
278- _ , err = os .Lstat (filepath .Join (dir , test .path ))
279- assert .ErrorIs (t , err , os .ErrNotExist , "whiteout should have removed path" ) //nolint:testifylint // assert.*Error* makes more sense
278+ if test .expectedErr != nil {
279+ assert .ErrorIsf (t , err , test .expectedErr , "UnpackEntry %q whiteout should fail with expected err" , hdr .Name ) //nolint:testifylint // assert.*Error* makes more sense
280+ } else {
281+ require .NoErrorf (t , err , "UnpackEntry %q whiteout" , hdr .Name )
282+ // Make sure that the path is gone.
283+ _ , err = os .Lstat (filepath .Join (dir , test .path ))
284+ assert .ErrorIs (t , err , os .ErrNotExist , "whiteout should have removed path" ) //nolint:testifylint // assert.*Error* makes more sense
285+ }
280286
281287 // Make sure the parent directory wasn't modified.
282288 fi , err := os .Lstat (filepath .Join (dir , rawDir ))
0 commit comments