Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 6bad1ff

Browse files
committed
[integration-test] add test case for load local
1 parent 1c030e3 commit 6bad1ff

File tree

4 files changed

+467
-26
lines changed

4 files changed

+467
-26
lines changed

integration-cli/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Integration test for hyper cli
3333
- [if test case will be supported in the future](#if-test-case-will-be-supported-in-the-future)
3434
- [After issues fixed](#after-issues-fixed)
3535

36+
- [Run test on localhost](#run-test-on-localhost)
37+
3638
<!-- /TOC -->
3739

3840
# Project status
@@ -292,3 +294,51 @@ ok github.com/hyperhq/hypercli/integration-cli ?s
292294

293295
- move the test case from `integration-cli/issue` to `integration-cli` dir
294296
- go to [start test](#start-test)
297+
298+
299+
# Run test on localhost
300+
301+
## prepare
302+
303+
```
304+
// ensure hyperhq and docker dir
305+
mkdir -p $GOPATH/src/github.com/{hyperhq,docker}
306+
307+
// clone and build hypercli
308+
cd $GOPATH/src/github.com/hyperhq
309+
git clone git@github.com:hyperhq/hypercli.git
310+
cd hypercli
311+
./build.sh
312+
313+
// copy hyper binary to /usr/bin/hyper
314+
sudo cp hyper/hyper /usr/bin/hyper
315+
316+
// create link
317+
cd $GOPATH/src/github.com/docker
318+
ln -s ../hyperhq/hypercli docker
319+
320+
// generate util.conf
321+
$ cd $GOPATH/src/github.com/hyperhq/hypercli
322+
$ git checkout integration-test
323+
$ cd integration-cli
324+
$ ./util.sh
325+
326+
// config util.conf
327+
$ vi util.conf
328+
HYPER_CONFIG=<$HOME/.hyper>
329+
ACCESS_KEY="<hyper access key>"
330+
SECRET_KEY="<hyper secret key>"
331+
```
332+
333+
## run test case
334+
335+
```
336+
// run all test cases
337+
$ ./util.sh test
338+
339+
// run specified test case
340+
$ ./util.sh test TestLoadFromLocalTar$
341+
342+
// run test cases start with specified prefix
343+
$ ./util.sh test TestLoadFromLocalTar
344+
```

integration-cli/docker_utils.go

100755100644
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/aws/aws-sdk-go/aws"
27+
"github.com/aws/aws-sdk-go/aws/credentials"
28+
"github.com/aws/aws-sdk-go/service/s3"
2629
"github.com/docker/docker/opts"
2730
"github.com/docker/docker/pkg/integration"
31+
"github.com/docker/docker/pkg/integration/checker"
2832
"github.com/docker/docker/pkg/ioutils"
2933
"github.com/docker/docker/pkg/stringutils"
3034
HyperCli "github.com/docker/engine-api/client"
3135
"github.com/docker/engine-api/types"
3236
"github.com/docker/go-connections/sockets"
3337
"github.com/docker/go-connections/tlsconfig"
3438
"github.com/go-check/check"
35-
"github.com/aws/aws-sdk-go/service/s3"
36-
"github.com/aws/aws-sdk-go/aws"
37-
"github.com/aws/aws-sdk-go/aws/credentials"
38-
"github.com/docker/docker/pkg/integration/checker"
3939
)
4040

4141
var flag_host = ""
@@ -622,7 +622,7 @@ func newRequestClient(method, endpoint string, data io.Reader, ct string) (*http
622622
client := httputil.NewClientConn(c, nil)
623623

624624
//save to postData
625-
postData := fmt.Sprintf("%v",data)
625+
postData := fmt.Sprintf("%v", data)
626626

627627
req, err := http.NewRequest(method, fmt.Sprintf("/v1.23%s", endpoint), data)
628628
if err != nil {
@@ -644,13 +644,13 @@ func newRequestClient(method, endpoint string, data io.Reader, ct string) (*http
644644
if endpoint == debugEndpoint {
645645
//output curl command line
646646
fmt.Println("\n--------------------------------------------------------------------------------------------")
647-
fmt.Printf("debugEndpoint: %v (expired after 5min)\n",debugEndpoint)
647+
fmt.Printf("debugEndpoint: %v (expired after 5min)\n", debugEndpoint)
648648
fmt.Println("--------------------------------------------------------------------------------------------")
649649
fmt.Println("curl -v -k \\")
650650
for k, v := range req.Header {
651651
fmt.Printf(" -H \"%v: %v\" \\\n", k, v[0])
652652
}
653-
fmt.Printf(" -X %v \\\n", method )
653+
fmt.Printf(" -X %v \\\n", method)
654654
if req.Body != nil {
655655
fmt.Printf(" -d '%v' \\\n", postData)
656656
}
@@ -778,7 +778,6 @@ func getAllSnapshots() ([]*types.Snapshot, error) {
778778
return snapshots.Snapshots, nil
779779
}
780780

781-
782781
func deleteAllVolumes() error {
783782
volumes, err := getAllVolumes()
784783
if err != nil {
@@ -934,6 +933,14 @@ func pullImageIfNotExist(image string) error {
934933
return nil
935934
}
936935

936+
func pathExist(_path string) bool {
937+
_, err := os.Stat(_path)
938+
if err != nil && os.IsNotExist(err) {
939+
return false
940+
}
941+
return true
942+
}
943+
937944
func dockerCmdWithError(args ...string) (string, int, error) {
938945
arg := []string{"--host=" + os.Getenv("DOCKER_HOST")}
939946
args = append(arg, args...)
@@ -1881,7 +1888,7 @@ func printTestDuration(start time.Time) {
18811888
fmt.Printf(" - %.6f sec\n", duration)
18821889
}
18831890

1884-
func generateS3PreSignedURL(region,s3bucket,s3key string) (string, error) {
1891+
func generateS3PreSignedURL(region, s3bucket, s3key string) (string, error) {
18851892

18861893
accessKey := os.Getenv("AWS_ACCESS_KEY")
18871894
secretKey := os.Getenv("AWS_SECRET_KEY")
@@ -1892,7 +1899,7 @@ func generateS3PreSignedURL(region,s3bucket,s3key string) (string, error) {
18921899

18931900
s3cli := s3.New(&aws.Config{
18941901
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
1895-
Region: &region,
1902+
Region: &region,
18961903
})
18971904

18981905
r, _ := s3cli.GetObjectRequest(&s3.GetObjectInput{
@@ -1917,30 +1924,29 @@ func getImageInspect(c *check.C, imageName string) *types.ImageInspect {
19171924
return &image
19181925
}
19191926

1920-
func ensureImageExist(c *check.C, imageName string){
1927+
func ensureImageExist(c *check.C, imageName string) {
19211928
for i := 0; i < 3; i++ {
19221929
if _err := pullImageIfNotExist(imageName); _err != nil {
1923-
c.Logf("couldn't find the %s image locally and failed to pull it, try againt\n",imageName)
1930+
c.Logf("couldn't find the %s image locally and failed to pull it, try againt\n", imageName)
19241931
} else {
19251932
break
19261933
}
19271934
}
19281935
}
19291936

19301937
//get containerId or imageId from hyper command output
1931-
func getIDfromOutput(c *check.C, output string)(string){
1938+
func getIDfromOutput(c *check.C, output string) string {
19321939
outAry := strings.Split(output, "\n")
1933-
c.Assert(len(outAry), checker.GreaterOrEqualThan,2)
1940+
c.Assert(len(outAry), checker.GreaterOrEqualThan, 2)
19341941
id := outAry[len(outAry)-2]
19351942
return strings.TrimSpace(id)
19361943
}
19371944

1938-
19391945
func checkImage(c *check.C, shouldExist bool, imageName string) {
19401946
images, _ := dockerCmd(c, "images", imageName)
19411947
if shouldExist {
19421948
c.Assert(images, checker.Contains, imageName)
19431949
} else {
19441950
c.Assert(images, check.Not(checker.Contains), imageName)
19451951
}
1946-
}
1952+
}

0 commit comments

Comments
 (0)