-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add api test for image load and save
Signed-off-by: xiechengsheng <[email protected]>
- Loading branch information
1 parent
f251319
commit 863e968
Showing
6 changed files
with
119 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
"github.com/alibaba/pouch/test/environment" | ||
"github.com/alibaba/pouch/test/request" | ||
|
||
"github.com/go-check/check" | ||
) | ||
|
||
// APIImageSaveLoadSuite is the test suite for image save and load API. | ||
type APIImageSaveLoadSuite struct{} | ||
|
||
func init() { | ||
check.Suite(&APIImageSaveLoadSuite{}) | ||
} | ||
|
||
// SetUpTest does common setup in the beginning of each test. | ||
func (suite *APIImageSaveLoadSuite) SetUpTest(c *check.C) { | ||
SkipIfFalse(c, environment.IsLinux) | ||
|
||
PullImage(c, helloworldImage) | ||
} | ||
|
||
// TestImageSaveLoadOk tests saving and loading images are OK. | ||
func (suite *APIImageSaveLoadSuite) TestImageSaveLoadOk(c *check.C) { | ||
before, err := request.Get("/images/" + helloworldImage + "/json") | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, before, 200) | ||
gotBefore := types.ImageInfo{} | ||
err = request.DecodeBody(&gotBefore, before.Body) | ||
c.Assert(err, check.IsNil) | ||
|
||
q := url.Values{} | ||
q.Set("name", helloworldImage) | ||
query := request.WithQuery(q) | ||
resp, err := request.Get("/images/save", query) | ||
c.Assert(err, check.IsNil) | ||
defer resp.Body.Close() | ||
|
||
loadImageName := "load-helloworld" | ||
q = url.Values{} | ||
q.Set("name", loadImageName) | ||
q.Set("quiet", "0") | ||
|
||
query = request.WithQuery(q) | ||
reader := request.WithRawData(resp.Body) | ||
header := request.WithHeader("Content-Type", "application/x-tar") | ||
|
||
resp, err = request.Post("/images/load", query, reader, header) | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 200) | ||
|
||
after, err := request.Get("/images/" + loadImageName + ":" + environment.HelloworldTag + "/json") | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, after, 200) | ||
defer request.Delete("/images/" + loadImageName + ":" + environment.HelloworldTag) | ||
|
||
gotAfter := types.ImageInfo{} | ||
err = request.DecodeBody(&gotAfter, after.Body) | ||
c.Assert(err, check.IsNil) | ||
|
||
c.Assert(gotBefore.ID, check.Equals, gotAfter.ID) | ||
c.Assert(gotBefore.CreatedAt, check.Equals, gotAfter.CreatedAt) | ||
c.Assert(gotBefore.Size, check.Equals, gotAfter.Size) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters