Skip to content

Commit 69854c4

Browse files
committed
cli/command/container: TestRunPullTermination: rewrite with streamformatter
This makes the test slightly closer to the actual code in the daemon producing the progress response; https://github.com/moby/moby/blob/cd844fd0b2047eff6854600d375545b3ec01de48/daemon/images/image_pull.go#L58-L70 https://github.com/moby/moby/blob/cd844fd0b2047eff6854600d375545b3ec01de48/daemon/internal/distribution/utils/progress.go#L14-L34 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 877a6ef commit 69854c4

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)