Skip to content

Commit 15aec73

Browse files
authored
Merge pull request #1386 from fuweid/bugfix_make_ci_happy
bugfix: make the PullImage test util work
2 parents 0df5157 + ec36ce2 commit 15aec73

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

test/main_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77

88
"github.com/alibaba/pouch/client"
9-
"github.com/alibaba/pouch/test/command"
109
"github.com/alibaba/pouch/test/environment"
1110
"github.com/go-check/check"
1211
)
@@ -27,8 +26,6 @@ func TestMain(m *testing.M) {
2726
}
2827
apiClient = commonAPIClient.(*client.APIClient)
2928

30-
command.PouchRun("pull", busyboxImage)
31-
3229
os.Exit(m.Run())
3330
}
3431

test/util_api.go

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package main
22

33
import (
44
"bufio"
5+
"encoding/json"
6+
"fmt"
7+
"io"
58
"net"
69
"net/http"
710
"net/url"
811
"time"
912

1013
"github.com/alibaba/pouch/apis/types"
14+
"github.com/alibaba/pouch/ctrd"
1115
"github.com/alibaba/pouch/test/request"
1216

1317
"github.com/go-check/check"
@@ -262,12 +266,43 @@ func PullImage(c *check.C, image string) {
262266
resp, err := request.Get("/images/" + image + "/json")
263267
c.Assert(err, check.IsNil)
264268

265-
if resp.StatusCode == 404 {
266-
q := url.Values{}
267-
q.Add("fromImage", image)
268-
query := request.WithQuery(q)
269-
resp, err = request.Post("/images/create", query)
270-
c.Assert(err, check.IsNil)
271-
c.Assert(resp.StatusCode, check.Equals, 200)
269+
if resp.StatusCode == http.StatusOK {
270+
resp.Body.Close()
271+
return
272272
}
273+
274+
q := url.Values{}
275+
q.Add("fromImage", image)
276+
resp, err = request.Post("/images/create", request.WithQuery(q))
277+
c.Assert(err, check.IsNil)
278+
c.Assert(resp.StatusCode, check.Equals, 200)
279+
280+
defer resp.Body.Close()
281+
c.Assert(fetchPullStatus(resp.Body), check.IsNil)
282+
}
283+
284+
func fetchPullStatus(r io.ReadCloser) error {
285+
dec := json.NewDecoder(r)
286+
if _, err := dec.Token(); err != nil {
287+
return fmt.Errorf("failed to read the opening token: %v", err)
288+
}
289+
290+
for dec.More() {
291+
var infos []ctrd.ProgressInfo
292+
293+
if err := dec.Decode(&infos); err != nil {
294+
return fmt.Errorf("failed to decode: %v", err)
295+
}
296+
297+
for _, info := range infos {
298+
if info.ErrorMessage != "" {
299+
return fmt.Errorf(info.ErrorMessage)
300+
}
301+
}
302+
}
303+
304+
if _, err := dec.Token(); err != nil {
305+
return fmt.Errorf("failed to read the closing token: %v", err)
306+
}
307+
return nil
273308
}

0 commit comments

Comments
 (0)