Browse code

Remove use of bufio in cli import tests

The use of bufio for writing without flushing can lead to an incomplete
writing of the tar and subsequent unexpected EOF when importing.

Signed-off-by: Derek McGowan <derek@mcg.dev>

Derek McGowan authored on 2024/12/25 15:01:05
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"bufio"
5 4
 	"compress/gzip"
6 5
 	"context"
7 6
 	"os"
... ...
@@ -66,7 +65,7 @@ func (s *DockerCLIImportSuite) TestImportFile(c *testing.T) {
66 66
 
67 67
 	icmd.RunCmd(icmd.Cmd{
68 68
 		Command: []string{dockerBinary, "export", "test-import"},
69
-		Stdout:  bufio.NewWriter(temporaryFile),
69
+		Stdout:  temporaryFile,
70 70
 	}).Assert(c, icmd.Success)
71 71
 
72 72
 	out := cli.DockerCmd(c, "import", temporaryFile.Name()).Combined()
... ...
@@ -110,7 +109,7 @@ func (s *DockerCLIImportSuite) TestImportFileWithMessage(c *testing.T) {
110 110
 
111 111
 	icmd.RunCmd(icmd.Cmd{
112 112
 		Command: []string{dockerBinary, "export", "test-import"},
113
-		Stdout:  bufio.NewWriter(temporaryFile),
113
+		Stdout:  temporaryFile,
114 114
 	}).Assert(c, icmd.Success)
115 115
 
116 116
 	message := "Testing commit message"
... ...
@@ -144,7 +143,7 @@ func (s *DockerCLIImportSuite) TestImportWithQuotedChanges(c *testing.T) {
144 144
 	assert.Assert(c, err == nil, "failed to create temporary file")
145 145
 	defer os.Remove(temporaryFile.Name())
146 146
 
147
-	cli.Docker(cli.Args("export", "test-import"), cli.WithStdout(bufio.NewWriter(temporaryFile))).Assert(c, icmd.Success)
147
+	cli.Docker(cli.Args("export", "test-import"), cli.WithStdout(temporaryFile)).Assert(c, icmd.Success)
148 148
 
149 149
 	result := cli.DockerCmd(c, "import", "-c", `ENTRYPOINT ["/bin/sh", "-c"]`, temporaryFile.Name())
150 150
 	imgRef := strings.TrimSpace(result.Stdout())