Skip to content

Commit 5f6dfb0

Browse files
authored
Merge pull request #6287 from thaJeztah/progress_test
cli/command/container: TestRunPullTermination: rewrite with streamformatter
2 parents c06074b + 69854c4 commit 5f6dfb0

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

cli/command/container/run_test.go

Lines changed: 9 additions & 17 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"
@@ -16,13 +14,13 @@ import (
1614
"github.com/docker/cli/cli/streams"
1715
"github.com/docker/cli/internal/test"
1816
"github.com/docker/cli/internal/test/notary"
17+
"github.com/moby/moby/api/pkg/progress"
18+
"github.com/moby/moby/api/pkg/streamformatter"
1919
"github.com/moby/moby/api/types"
2020
"github.com/moby/moby/api/types/container"
2121
"github.com/moby/moby/api/types/image"
22-
"github.com/moby/moby/api/types/jsonstream"
2322
"github.com/moby/moby/api/types/network"
2423
"github.com/moby/moby/client"
25-
"github.com/moby/moby/client/pkg/jsonmessage"
2624
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2725
"github.com/spf13/pflag"
2826
"gotest.tools/v3/assert"
@@ -244,25 +242,19 @@ func TestRunPullTermination(t *testing.T) {
244242
_ = server.Close()
245243
})
246244
go func() {
247-
enc := json.NewEncoder(server)
245+
id := test.RandomID()[:12] // short-ID
246+
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
248247
for i := 0; i < 100; i++ {
249248
select {
250249
case <-ctx.Done():
251250
assert.NilError(t, server.Close(), "failed to close imageCreateFunc server")
252251
return
253252
default:
254-
assert.NilError(t, enc.Encode(jsonmessage.JSONMessage{
255-
Status: "Downloading",
256-
ID: fmt.Sprintf("id-%d", i),
257-
TimeNano: time.Now().UnixNano(),
258-
Time: time.Now().Unix(),
259-
Progress: &jsonmessage.JSONProgress{
260-
Progress: jsonstream.Progress{
261-
Current: int64(i),
262-
Total: 100,
263-
Start: 0,
264-
},
265-
},
253+
assert.NilError(t, progressOutput.WriteProgress(progress.Progress{
254+
ID: id,
255+
Message: "Downloading",
256+
Current: int64(i),
257+
Total: 100,
266258
}))
267259
time.Sleep(100 * time.Millisecond)
268260
}

0 commit comments

Comments
 (0)