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

Commit 241f751

Browse files
authored
Merge pull request #236 from Jimmy-Xu/fix-integration-test
fix test case
2 parents c9c8ca5 + 091e281 commit 241f751

File tree

4 files changed

+82
-45
lines changed

4 files changed

+82
-45
lines changed

integration-cli/README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Functional test for hyper cli.
3131
- [run test in docker container](#run-test-in-docker-container)
3232
- [run test via util.sh](#run-test-via-utilsh)
3333
- [run test via docker cli](#run-test-via-docker-cli)
34+
- [run test via hyper cli](#run-test-via-hyper-cli)
3435

3536
<!-- /TOC -->
3637

@@ -332,20 +333,27 @@ $ ./util.sh qa "#222"
332333

333334
#### run test via docker cli
334335

335-
> ACCESS_KEY and SECRET_KEY are required
336+
Required parameters:
337+
338+
`APIROUTER`: apirouter entrypoint
339+
`REGION`: could be us-west-1(zl2), eu-central-1(eu1), RegionOne(packet)
340+
`ACCESS_KEY`,`SECRET_KEY`: Hyper credential for test
341+
`BRANCH`: hyper cli branch name or PR number
336342

337343
```
338-
//test `master` branch with `zenlayer` apirouter
339-
$ export ACCESS_KEY="xxxxxxxx"
340-
$ export SECRET_KEY="xxxxxxxxxxxxxxxxxxxx"
344+
//test `master` branch of hypercli with `eu-west-1` apirouter
341345
$ docker run -it --rm \
342346
-e ACCESS_KEY=${ACCESS_KEY} \
343347
-e SECRET_KEY=${SECRET_KEY} \
348+
-e DOCKER_HOST=tcp://us-west-1.hyper.sh:443 \
349+
-e REGION=us-west-1 \
350+
-e BRANCH=master \
344351
hyperhq/hypercli-auto-test:qa go test -check.f TestCli -timeout 180m
345352
346-
347353
//test `specified PR`
348354
$ docker run -it --rm \
355+
-e DOCKER_HOST=${APIROUTER} \
356+
-e REGION=${REGION} \
349357
-e ACCESS_KEY=${ACCESS_KEY} \
350358
-e SECRET_KEY=${SECRET_KEY} \
351359
-e BRANCH="#221" \
@@ -354,40 +362,47 @@ $ docker run -it --rm \
354362
355363
//test `specified case name`
356364
$ docker run -it --rm \
365+
-e DOCKER_HOST=${APIROUTER} \
366+
-e REGION=${REGION} \
357367
-e ACCESS_KEY="${ACCESS_KEY}" \
358368
-e SECRET_KEY="${SECRET_KEY}" \
369+
-e BRANCH=${BRANCH} \
359370
hyperhq/hypercli-auto-test:qa go test -check.f 'TestCliInfo|TestCliFip' -timeout 180m
360371
361372
362-
//test `specified branch` with `packet` apirouter
373+
//test with `packet` apirouter
363374
$ docker run -it --rm \
364375
-e ACCESS_KEY=${ACCESS_KEY} \
365376
-e SECRET_KEY=${SECRET_KEY} \
366-
-e BRANCH=integration-test \
377+
-e BRANCH=${BRANCH} \
367378
-e DOCKER_HOST=tcp://147.75.x.x:6443 \
379+
-e REGION=RegionOne \
368380
hyperhq/hypercli-auto-test:qa go test -check.f TestCli -timeout 180m
369381
370382
371383
//test with http proxy
372384
$ docker run -it --rm \
385+
-e DOCKER_HOST=${APIROUTER} \
386+
-e REGION=${REGION} \
373387
-e ACCESS_KEY=${ACCESS_KEY} \
374388
-e SECRET_KEY=${SECRET_KEY} \
389+
-e BRANCH=${BRANCH} \
375390
-e http_proxy=${http_proxy} \
376391
-e https_proxy=${https_proxy} \
377392
hyperhq/hypercli-auto-test:qa go test -check.f TestCliInfo
378393
379-
//test with region(region name could be us-west-1/eu-central-1)
380-
$ docker run -it --rm \
381-
-e ACCESS_KEY=${ACCESS_KEY} \
382-
-e SECRET_KEY=${SECRET_KEY} \
383-
-e REGION=${REGION} \
384-
-e http_proxy=${http_proxy} \
385-
-e https_proxy=${https_proxy} \
386-
hyperhq/hypercli-auto-test:qa go test -check.f TestCliInfo
387394
388395
//test basic test case only
389396
$ docker run -it --rm \
397+
-e DOCKER_HOST=${APIROUTER} \
398+
-e REGION=${REGION} \
390399
-e ACCESS_KEY=${ACCESS_KEY} \
391400
-e SECRET_KEY=${SECRET_KEY} \
401+
-e BRANCH=${BRANCH} \
392402
hyperhq/hypercli-auto-test:qa go test -check.f "TestCli.*Basic" -timeout 180m
403+
393404
```
405+
406+
#### run test via hyper cli
407+
408+
Just replace `docker` with `hyper` in command line.

integration-cli/hyper_cli_region_test.go renamed to integration-cli/final/cli/hyper_cli_region_test.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,10 @@ func (s *DockerSuite) TestCliRegionBasic(c *check.C) {
2828
anotherRegion = "us-west-1"
2929
}
3030

31-
//delete busybox
32-
cmd := exec.Command(dockerBinary, "rmi", "-f", "busybox")
33-
runCommandWithOutput(cmd)
34-
cmd = exec.Command(dockerBinary, "images", "busybox")
35-
out, _, _ := runCommandWithOutput(cmd)
36-
c.Assert(out, checker.Not(checker.Contains), "busybox")
37-
//delete ubuntu
38-
cmd = exec.Command(dockerBinary, "--region", anotherRegion, "rmi", "-f", "ubuntu")
39-
runCommandWithOutput(cmd)
40-
cmd = exec.Command(dockerBinary, "--region", anotherRegion, "images", "ubuntu")
41-
out, _, _ = runCommandWithOutput(cmd)
42-
c.Assert(out, checker.Not(checker.Contains), "ubuntu")
43-
4431
////////////////////////////////////////////
4532
//pull image with default region
46-
cmd = exec.Command(dockerBinary, "pull", "busybox")
47-
out, _, err = runCommandWithOutput(cmd)
33+
cmd := exec.Command(dockerBinary, "pull", "busybox")
34+
out, _, err := runCommandWithOutput(cmd)
4835
if err != nil {
4936
c.Fatal(err, out)
5037
}

integration-cli/hyper_cli_config_test.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import (
99
"github.com/go-check/check"
1010
"github.com/hyperhq/hypercli/cliconfig"
1111
"github.com/hyperhq/hypercli/pkg/homedir"
12+
"os/exec"
1213
)
1314

1415
func (s *DockerSuite) TestCliConfigAndRewrite(c *check.C) {
1516
printTestCaseName()
1617
defer printTestDuration(time.Now())
1718

18-
out, _ := dockerCmd(c, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "xx", "--secretkey", "xxxx", "tcp://127.0.0.1:6443")
19+
cmd := exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "xx", "--secretkey", "xxxx", "tcp://127.0.0.1:6443")
20+
out, _, _, err := runCommandWithStdoutStderr(cmd)
21+
c.Assert(err, checker.IsNil)
1922
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
2023

2124
configDir := filepath.Join(homedir.Get(), ".hyper")
@@ -24,20 +27,37 @@ func (s *DockerSuite) TestCliConfigAndRewrite(c *check.C) {
2427
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6443"].AccessKey, checker.Equals, "xx", check.Commentf("Should get xx, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6443"].AccessKey))
2528
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6443"].SecretKey, checker.Equals, "xxxx", check.Commentf("Should get xxxx, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6443"].SecretKey))
2629

27-
out, _ = dockerCmd(c, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "yy", "--secretkey", "yyyy", "tcp://127.0.0.1:6443")
30+
31+
cmd = exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "yy", "--secretkey", "yyyy", "tcp://127.0.0.1:6443")
32+
out, _, _, err = runCommandWithStdoutStderr(cmd)
33+
c.Assert(err, checker.IsNil)
2834
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
2935

3036
conf, err = cliconfig.Load(configDir)
3137
c.Assert(err, checker.IsNil)
3238
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6443"].AccessKey, checker.Equals, "yy", check.Commentf("Should get yy, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6443"].AccessKey))
3339
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6443"].SecretKey, checker.Equals, "yyyy", check.Commentf("Should get yyyy, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6443"].SecretKey))
40+
41+
//patch
42+
cmd = exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", os.Getenv("ACCESS_KEY"), "--secretkey", os.Getenv("SECRET_KEY"), os.Getenv("DOCKER_HOST"))
43+
out, _, _, err = runCommandWithStdoutStderr(cmd)
44+
c.Assert(err, checker.IsNil)
45+
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
46+
47+
cmd = exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", os.Getenv("ACCESS_KEY"), "--secretkey", os.Getenv("SECRET_KEY"))
48+
out, _, _, err = runCommandWithStdoutStderr(cmd)
49+
c.Assert(err, checker.IsNil)
50+
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
3451
}
3552

3653
func (s *DockerSuite) TestCliConfigMultiHostBasic(c *check.C) {
3754
printTestCaseName()
3855
defer printTestDuration(time.Now())
3956

40-
out, _ := dockerCmd(c, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "xx", "--secretkey", "xxxx", "tcp://127.0.0.1:6443")
57+
58+
cmd := exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "xx", "--secretkey", "xxxx", "tcp://127.0.0.1:6443")
59+
out, _, _, err := runCommandWithStdoutStderr(cmd)
60+
c.Assert(err, checker.IsNil)
4161
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
4262

4363
configDir := filepath.Join(homedir.Get(), ".hyper")
@@ -46,11 +66,24 @@ func (s *DockerSuite) TestCliConfigMultiHostBasic(c *check.C) {
4666
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6443"].AccessKey, checker.Equals, "xx", check.Commentf("Should get xx, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6443"].AccessKey))
4767
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6443"].SecretKey, checker.Equals, "xxxx", check.Commentf("Should get xxxx, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6443"].SecretKey))
4868

49-
out, _ = dockerCmd(c, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "yy", "--secretkey", "yyyy", "tcp://127.0.0.1:6444")
69+
cmd = exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", "yy", "--secretkey", "yyyy", "tcp://127.0.0.1:6444")
70+
out, _, _, err = runCommandWithStdoutStderr(cmd)
71+
c.Assert(err, checker.IsNil)
5072
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
5173

5274
conf, err = cliconfig.Load(configDir)
5375
c.Assert(err, checker.IsNil)
5476
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6444"].AccessKey, checker.Equals, "yy", check.Commentf("Should get yy, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6444"].AccessKey))
5577
c.Assert(conf.CloudConfig["tcp://127.0.0.1:6444"].SecretKey, checker.Equals, "yyyy", check.Commentf("Should get yyyy, but get %s\n", conf.CloudConfig["tcp://127.0.0.1:6444"].SecretKey))
78+
79+
//patch
80+
cmd = exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", os.Getenv("ACCESS_KEY"), "--secretkey", os.Getenv("SECRET_KEY"), os.Getenv("DOCKER_HOST"))
81+
out, _, _, err = runCommandWithStdoutStderr(cmd)
82+
c.Assert(err, checker.IsNil)
83+
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
84+
85+
cmd = exec.Command(dockerBinary, "config", "--default-region" , os.Getenv("REGION"), "--accesskey", os.Getenv("ACCESS_KEY"), "--secretkey", os.Getenv("SECRET_KEY"))
86+
out, _, _, err = runCommandWithStdoutStderr(cmd)
87+
c.Assert(err, checker.IsNil)
88+
c.Assert(out, checker.Contains, "WARNING: Your login credentials has been saved in "+homedir.Get()+"/.hyper/config.json")
5689
}

integration-cli/util.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ function show_usage() {
77
cat <<EOF
88
Usage: ./util.sh <action>
99
<action>:
10-
build-dev # build docker image 'hyperhq/hypercl' from Dockerfile.dev
11-
build-qa # build docker image 'hyperhq/hypercl' from Dockerfile.qa
12-
make # make hyper cli in container
13-
enter # enter container from hyperhq/hhypercli-auto-test:dev
14-
qa <branch> # run test case in hyperhq/hhypercli-auto-test:qa, default branch is 'master'
15-
test # test on host
10+
build-dev # build docker image 'hyperhq/hypercl' from Dockerfile.dev
11+
build-qa # build docker image 'hyperhq/hypercl' from Dockerfile.qa
12+
make # make hyper cli in container
13+
enter-dev # enter container from hyperhq/hhypercli-auto-test:dev
14+
enter-qa <branch> # enter container from hyperhq/hhypercli-auto-test:qa, default branch is 'master'
15+
test # test on host
1616
EOF
1717
}
1818

@@ -68,12 +68,12 @@ case $1 in
6868
-v $(pwd)/../:/go/src/github.com/hyperhq/hypercli \
6969
${IMAGE_NAME}:dev ./build.sh
7070
;;
71-
enter)
71+
enter-dev)
7272
docker run -it --rm \
7373
-e DOCKER_HOST=${HYPER_HOST} \
74+
-e REGION=${REGION} \
7475
-e ACCESS_KEY=${ACCESS_KEY} \
7576
-e SECRET_KEY=${SECRET_KEY} \
76-
-e REGION=${REGION} \
7777
-e AWS_ACCESS_KEY=${AWS_ACCESS_KEY} \
7878
-e AWS_SECRET_KEY=${AWS_SECRET_KEY} \
7979
-e URL_WITH_BASIC_AUTH=${URL_WITH_BASIC_AUTH} \
@@ -84,22 +84,24 @@ case $1 in
8484
-v $(pwd)/../:/go/src/github.com/hyperhq/hypercli \
8585
${IMAGE_NAME}:dev zsh
8686
;;
87-
qa)
87+
enter-qa)
8888
BRANCH=$2
8989
if [ "$BRANCH" == "" ];then
9090
BRANCH="master"
9191
fi
9292
docker run -it --rm \
9393
-e http_proxy=${http_proxy} \
9494
-e https_proxy=${https_proxy} \
95-
-e BRANCH=${BRANCH} \
9695
-e DOCKER_HOST=${HYPER_HOST} \
96+
-e REGION=${REGION} \
97+
-e BRANCH=${BRANCH} \
9798
-e ACCESS_KEY=${ACCESS_KEY} \
9899
-e SECRET_KEY=${SECRET_KEY} \
99100
-e DOCKERHUB_EMAIL=${DOCKERHUB_EMAIL} \
100101
-e DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME} \
101102
-e DOCKERHUB_PASSWD=${DOCKERHUB_PASSWD} \
102-
${IMAGE_NAME}:qa go test -check.f TestCli -timeout 180m
103+
${IMAGE_NAME}:qa /bin/bash
104+
# ${IMAGE_NAME}:qa go test -check.f TestCli -timeout 180m
103105
;;
104106
test)
105107
export DOCKER_HOST=${HYPER_HOST}

0 commit comments

Comments
 (0)