Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions internal/jsonstream/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package jsonstream

import (
"context"
"encoding/json"
"fmt"
"io"
"testing"
"time"

"github.com/docker/cli/cli/streams"
"github.com/moby/moby/api/types/jsonstream"
"github.com/docker/cli/internal/test"
"github.com/moby/moby/api/pkg/progress"
"github.com/moby/moby/api/pkg/streamformatter"
"gotest.tools/v3/assert"
)

Expand All @@ -23,25 +23,19 @@ func TestDisplay(t *testing.T) {
})

go func() {
enc := json.NewEncoder(server)
id := test.RandomID()[:12] // short-ID
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
for i := 0; i < 100; i++ {
select {
case <-ctx.Done():
assert.NilError(t, server.Close(), "failed to close jsonmessage server")
return
default:
err := enc.Encode(JSONMessage{
Status: "Downloading",
ID: fmt.Sprintf("id-%d", i),
TimeNano: time.Now().UnixNano(),
Time: time.Now().Unix(),
Progress: &JSONProgress{
Progress: jsonstream.Progress{
Current: int64(i),
Total: 100,
Start: 0,
},
},
err := progressOutput.WriteProgress(progress.Progress{
ID: id,
Message: "Downloading",
Current: int64(i),
Total: 100,
})
if err != nil {
break
Expand Down
Loading