Skip to content

Commit 709478c

Browse files
committed
Fix pkg/jsonmessage.TestProgress panic
Fix moby#23112 Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
1 parent ef42e2f commit 709478c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/jsonmessage/jsonmessage_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func TestError(t *testing.T) {
1919
}
2020

2121
func TestProgress(t *testing.T) {
22+
termsz, err := term.GetWinsize(0)
23+
if err != nil {
24+
// we can safely ignore the err here
25+
termsz = nil
26+
}
2227
jp := JSONProgress{}
2328
if jp.String() != "" {
2429
t.Fatalf("Expected empty string, got '%s'", jp.String())
@@ -31,6 +36,9 @@ func TestProgress(t *testing.T) {
3136
}
3237

3338
expectedStart := "[==========> ] 20 B/100 B"
39+
if termsz != nil && termsz.Width <= 110 {
40+
expectedStart = " 20 B/100 B"
41+
}
3442
jp3 := JSONProgress{Current: 20, Total: 100, Start: time.Now().Unix()}
3543
// Just look at the start of the string
3644
// (the remaining time is really hard to test -_-)
@@ -39,13 +47,19 @@ func TestProgress(t *testing.T) {
3947
}
4048

4149
expected = "[=========================> ] 50 B/100 B"
50+
if termsz != nil && termsz.Width <= 110 {
51+
expected = " 50 B/100 B"
52+
}
4253
jp4 := JSONProgress{Current: 50, Total: 100}
4354
if jp4.String() != expected {
4455
t.Fatalf("Expected %q, got %q", expected, jp4.String())
4556
}
4657

4758
// this number can't be negative gh#7136
4859
expected = "[==================================================>] 50 B"
60+
if termsz != nil && termsz.Width <= 110 {
61+
expected = " 50 B"
62+
}
4963
jp5 := JSONProgress{Current: 50, Total: 40}
5064
if jp5.String() != expected {
5165
t.Fatalf("Expected %q, got %q", expected, jp5.String())

0 commit comments

Comments
 (0)