Skip to content

Commit 5579335

Browse files
authored
Merge pull request #6295 from thaJeztah/less_jsonmessage
internal/jsonstream: TestDisplay use streamformatter
2 parents 32b983a + b21139c commit 5579335

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

internal/jsonstream/display_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package jsonstream
22

33
import (
44
"context"
5-
"encoding/json"
6-
"fmt"
75
"io"
86
"testing"
97
"time"
108

119
"github.com/docker/cli/cli/streams"
12-
"github.com/moby/moby/api/types/jsonstream"
10+
"github.com/docker/cli/internal/test"
11+
"github.com/moby/moby/client/pkg/progress"
12+
"github.com/moby/moby/client/pkg/streamformatter"
1313
"gotest.tools/v3/assert"
1414
)
1515

@@ -23,21 +23,19 @@ func TestDisplay(t *testing.T) {
2323
})
2424

2525
go func() {
26-
enc := json.NewEncoder(server)
26+
id := test.RandomID()[:12] // short-ID
27+
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
2728
for i := 0; i < 100; i++ {
2829
select {
2930
case <-ctx.Done():
3031
assert.NilError(t, server.Close(), "failed to close jsonmessage server")
3132
return
3233
default:
33-
err := enc.Encode(JSONMessage{
34-
Status: "Downloading",
35-
ID: fmt.Sprintf("id-%d", i),
36-
Progress: &jsonstream.Progress{
37-
Current: int64(i),
38-
Total: 100,
39-
Start: 0,
40-
},
34+
err := progressOutput.WriteProgress(progress.Progress{
35+
ID: id,
36+
Message: "Downloading",
37+
Current: int64(i),
38+
Total: 100,
4139
})
4240
if err != nil {
4341
break

0 commit comments

Comments
 (0)