Skip to content

Commit 0e474e3

Browse files
committed
[28.x] 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 This is a modified version of 69854c4 with some changes specific to the 28.x branch (the variant on master had some patches for the moby/api and moby/client transition). Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 69854c4) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 6adde56 commit 0e474e3

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)