@@ -65,6 +65,34 @@ func TestCopyToContainerPathDoesNotExist(t *testing.T) {
6565func TestCopyEmptyFile (t * testing.T ) {
6666 defer setupTest (t )()
6767
68+ ctx := context .Background ()
69+ apiclient := testEnv .APIClient ()
70+ cid := container .Create (ctx , t , apiclient )
71+
72+ // empty content
73+ dstDir , _ := makeEmptyArchive (t )
74+ err := apiclient .CopyToContainer (ctx , cid , dstDir , bytes .NewReader ([]byte ("" )), types.CopyToContainerOptions {})
75+ assert .NilError (t , err )
76+
77+ // tar with empty file
78+ dstDir , preparedArchive := makeEmptyArchive (t )
79+ err = apiclient .CopyToContainer (ctx , cid , dstDir , preparedArchive , types.CopyToContainerOptions {})
80+ assert .NilError (t , err )
81+
82+ // tar with empty file archive mode
83+ dstDir , preparedArchive = makeEmptyArchive (t )
84+ err = apiclient .CopyToContainer (ctx , cid , dstDir , preparedArchive , types.CopyToContainerOptions {
85+ CopyUIDGID : true ,
86+ })
87+ assert .NilError (t , err )
88+
89+ // copy from empty file
90+ rdr , _ , err := apiclient .CopyFromContainer (ctx , cid , dstDir )
91+ assert .NilError (t , err )
92+ defer rdr .Close ()
93+ }
94+
95+ func makeEmptyArchive (t * testing.T ) (string , io.ReadCloser ) {
6896 tmpDir := t .TempDir ()
6997 srcPath := filepath .Join (tmpDir , "empty-file.txt" )
7098 err := os .WriteFile (srcPath , []byte ("" ), 0400 )
@@ -77,30 +105,18 @@ func TestCopyEmptyFile(t *testing.T) {
77105
78106 srcArchive , err := archive .TarResource (srcInfo )
79107 assert .NilError (t , err )
80- defer srcArchive .Close ()
108+ t .Cleanup (func () {
109+ srcArchive .Close ()
110+ })
81111
82112 ctrPath := "/empty-file.txt"
83113 dstInfo := archive.CopyInfo {Path : ctrPath }
84114 dstDir , preparedArchive , err := archive .PrepareArchiveCopy (srcArchive , srcInfo , dstInfo )
85115 assert .NilError (t , err )
86- defer preparedArchive .Close ()
87-
88- ctx := context .Background ()
89- apiclient := testEnv .APIClient ()
90- cid := container .Create (ctx , t , apiclient )
91-
92- // empty content
93- err = apiclient .CopyToContainer (ctx , cid , dstDir , bytes .NewReader ([]byte ("" )), types.CopyToContainerOptions {})
94- assert .NilError (t , err )
95-
96- // tar with empty file
97- err = apiclient .CopyToContainer (ctx , cid , dstDir , preparedArchive , types.CopyToContainerOptions {})
98- assert .NilError (t , err )
99-
100- // copy from empty file
101- rdr , _ , err := apiclient .CopyFromContainer (ctx , cid , dstDir )
102- assert .NilError (t , err )
103- defer rdr .Close ()
116+ t .Cleanup (func () {
117+ preparedArchive .Close ()
118+ })
119+ return dstDir , preparedArchive
104120}
105121
106122func TestCopyToContainerPathIsNotDir (t * testing.T ) {
0 commit comments