Skip to content

Commit e3f671a

Browse files
austinvazquezclaude
andcommitted
Refactor to remove dependency on github.com/moby/moby/pkg/progress
Co-authored-by: Claude <[email protected]> Signed-off-by: Austin Vazquez <[email protected]>
1 parent 309aff2 commit e3f671a

File tree

12 files changed

+82
-9
lines changed

12 files changed

+82
-9
lines changed

cli/command/container/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
"github.com/creack/pty"
1313
"github.com/docker/cli/cli"
1414
"github.com/docker/cli/cli/streams"
15+
"github.com/docker/cli/internal/progress"
1516
"github.com/docker/cli/internal/streamformatter"
1617
"github.com/docker/cli/internal/test"
1718
"github.com/docker/cli/internal/test/notary"
18-
"github.com/moby/moby/api/pkg/progress"
1919
"github.com/moby/moby/api/types"
2020
"github.com/moby/moby/api/types/container"
2121
"github.com/moby/moby/api/types/network"

cli/command/image/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
"github.com/docker/cli/cli/command/image/build"
2020
"github.com/docker/cli/cli/streams"
2121
"github.com/docker/cli/internal/jsonstream"
22+
"github.com/docker/cli/internal/progress"
2223
"github.com/docker/cli/internal/streamformatter"
2324
"github.com/docker/cli/opts"
2425
"github.com/moby/go-archive"
25-
"github.com/moby/moby/api/pkg/progress"
2626
buildtypes "github.com/moby/moby/api/types/build"
2727
"github.com/moby/moby/api/types/container"
2828
registrytypes "github.com/moby/moby/api/types/registry"

cli/command/image/build/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
"time"
1919

2020
"github.com/docker/cli/cli/command/image/build/internal/git"
21+
"github.com/docker/cli/internal/progress"
2122
"github.com/docker/cli/internal/streamformatter"
2223
"github.com/moby/go-archive"
2324
"github.com/moby/go-archive/compression"
24-
"github.com/moby/moby/api/pkg/progress"
2525
"github.com/moby/patternmatcher"
2626
)
2727

cli/command/service/progress/progress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"time"
1313

1414
"github.com/docker/cli/cli/command/formatter"
15+
"github.com/docker/cli/internal/progress"
1516
"github.com/docker/cli/internal/streamformatter"
16-
"github.com/moby/moby/api/pkg/progress"
1717
"github.com/moby/moby/api/types/swarm"
1818
"github.com/moby/moby/client"
1919
)

cli/command/service/progress/progress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strconv"
66
"testing"
77

8-
"github.com/moby/moby/api/pkg/progress"
8+
"github.com/docker/cli/internal/progress"
99
"github.com/moby/moby/api/types/swarm"
1010
"gotest.tools/v3/assert"
1111
is "gotest.tools/v3/assert/cmp"

cli/command/swarm/progress/root_rotation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"os/signal"
99
"time"
1010

11+
"github.com/docker/cli/internal/progress"
1112
"github.com/docker/cli/internal/streamformatter"
12-
"github.com/moby/moby/api/pkg/progress"
1313
"github.com/moby/moby/api/types/swarm"
1414
"github.com/moby/moby/client"
1515
"github.com/opencontainers/go-digest"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package progress
2+
3+
import (
4+
"bytes"
5+
"io"
6+
"testing"
7+
)
8+
9+
func TestOutputOnPrematureClose(t *testing.T) {
10+
content := []byte("TESTING")
11+
reader := io.NopCloser(bytes.NewReader(content))
12+
progressChan := make(chan Progress, 10)
13+
14+
pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read")
15+
16+
part := make([]byte, 4)
17+
_, err := io.ReadFull(pr, part)
18+
if err != nil {
19+
pr.Close()
20+
t.Fatal(err)
21+
}
22+
23+
drainLoop:
24+
for {
25+
select {
26+
case <-progressChan:
27+
default:
28+
break drainLoop
29+
}
30+
}
31+
32+
pr.Close()
33+
34+
select {
35+
case <-progressChan:
36+
default:
37+
t.Fatalf("Expected some output when closing prematurely")
38+
}
39+
}
40+
41+
func TestCompleteSilently(t *testing.T) {
42+
content := []byte("TESTING")
43+
reader := io.NopCloser(bytes.NewReader(content))
44+
progressChan := make(chan Progress, 10)
45+
46+
pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read")
47+
48+
out, err := io.ReadAll(pr)
49+
if err != nil {
50+
pr.Close()
51+
t.Fatal(err)
52+
}
53+
if string(out) != "TESTING" {
54+
pr.Close()
55+
t.Fatalf("Unexpected output %q from reader", string(out))
56+
}
57+
58+
drainLoop:
59+
for {
60+
select {
61+
case <-progressChan:
62+
default:
63+
break drainLoop
64+
}
65+
}
66+
67+
pr.Close()
68+
69+
select {
70+
case <-progressChan:
71+
t.Fatalf("Should have closed silently when read is complete")
72+
default:
73+
}
74+
}

internal/streamformatter/streamformatter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"sync"
1010
"time"
1111

12+
"github.com/docker/cli/internal/progress"
1213
"github.com/docker/go-units"
13-
"github.com/moby/moby/api/pkg/progress"
1414
"github.com/moby/moby/api/types/jsonstream"
1515
)
1616

0 commit comments

Comments
 (0)