Skip to content

Commit 4313a2b

Browse files
authored
Merge pull request #6294 from thaJeztah/28.x_backport_progress_test
[28.x] cli/command/container: TestRunPullTermination: rewrite with streamformatter
2 parents 20c34ef + 0e474e3 commit 4313a2b

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

cli/command/container/run_test.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package container
22

33
import (
44
"context"
5-
"encoding/json"
65
"errors"
7-
"fmt"
86
"io"
97
"net"
108
"syscall"
@@ -20,7 +18,8 @@ import (
2018
"github.com/docker/docker/api/types/container"
2119
"github.com/docker/docker/api/types/image"
2220
"github.com/docker/docker/api/types/network"
23-
"github.com/docker/docker/pkg/jsonmessage"
21+
"github.com/docker/docker/pkg/progress"
22+
"github.com/docker/docker/pkg/streamformatter"
2423
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2524
"github.com/spf13/pflag"
2625
"gotest.tools/v3/assert"
@@ -242,23 +241,19 @@ func TestRunPullTermination(t *testing.T) {
242241
_ = server.Close()
243242
})
244243
go func() {
245-
enc := json.NewEncoder(server)
244+
id := test.RandomID()[:12] // short-ID
245+
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
246246
for i := 0; i < 100; i++ {
247247
select {
248248
case <-ctx.Done():
249249
assert.NilError(t, server.Close(), "failed to close imageCreateFunc server")
250250
return
251251
default:
252-
assert.NilError(t, enc.Encode(jsonmessage.JSONMessage{
253-
Status: "Downloading",
254-
ID: fmt.Sprintf("id-%d", i),
255-
TimeNano: time.Now().UnixNano(),
256-
Time: time.Now().Unix(),
257-
Progress: &jsonmessage.JSONProgress{
258-
Current: int64(i),
259-
Total: 100,
260-
Start: 0,
261-
},
252+
assert.NilError(t, progressOutput.WriteProgress(progress.Progress{
253+
ID: id,
254+
Message: "Downloading",
255+
Current: int64(i),
256+
Total: 100,
262257
}))
263258
time.Sleep(100 * time.Millisecond)
264259
}

0 commit comments

Comments
 (0)