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

Commit 7a33022

Browse files
committed
fix var name and integration test
Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
1 parent 7ed9937 commit 7a33022

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

api/handlers.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,43 +72,41 @@ func getImages(c *context, w http.ResponseWriter, r *http.Request) {
7272

7373
// find an engine which has all images
7474
// Engine.Addr : [found names]
75-
dict := make(map[string][]string)
76-
bFoundEngine := false
75+
imageMap := make(map[string][]string)
7776
var foundEngineAddr string
7877
for _, image := range c.cluster.Images() {
7978
for _, name := range names {
8079
if image.Match(name) {
8180
// check if engine addr already exists
82-
value, exists := dict[image.Engine.Addr]
81+
value, exists := imageMap[image.Engine.Addr]
8382
if exists {
8483
// check if name already exists
85-
found := false
84+
nameAlreadyExisted := false
8685
for _, tempName := range value {
8786
if tempName == name {
88-
found = true
87+
nameAlreadyExisted = true
8988
}
9089
}
91-
if found == false {
92-
dict[image.Engine.Addr] = append(value, name)
93-
if len(names) == len(dict[image.Engine.Addr]) {
94-
bFoundEngine = true
90+
if nameAlreadyExisted == false {
91+
imageMap[image.Engine.Addr] = append(value, name)
92+
if len(names) == len(imageMap[image.Engine.Addr]) {
9593
foundEngineAddr = image.Engine.Addr
9694
}
9795
}
9896
} else {
99-
dict[image.Engine.Addr] = []string{name}
97+
imageMap[image.Engine.Addr] = []string{name}
10098
}
10199
}
102-
if bFoundEngine {
100+
if foundEngineAddr != "" {
103101
break
104102
}
105103
}
106-
if bFoundEngine {
104+
if foundEngineAddr != "" {
107105
break
108106
}
109107
}
110108

111-
if bFoundEngine {
109+
if foundEngineAddr != "" {
112110
proxy(c.tlsConfig, foundEngineAddr, w, r)
113111
} else {
114112
httpError(w, fmt.Sprintf("Not found an engine which has all images: %s", names), http.StatusNotFound)

test/integration/api/save.bats

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,46 @@ function teardown() {
4343
rm -f $temp_file_name_o
4444
}
4545

46-
@test "docker save muti-images" {
47-
start_docker_with_busybox 1
46+
@test "docker save multi-images" {
47+
start_docker_with_busybox 2
4848
start_docker 1
49-
swarm_manage
50-
5149
# tag busybox
52-
run docker_swarm tag busybox testimage
53-
[ "$status" -eq 0 ]
50+
docker -H ${HOSTS[0]} tag busybox test1
51+
docker -H ${HOSTS[1]} tag busybox test2
52+
53+
# start manage
54+
swarm_manage
5455

5556
# make sure image exists
5657
run docker_swarm images
5758
[ "$status" -eq 0 ]
5859
[[ "${output}" == *"busybox"* ]]
59-
[[ "${output}" == *"testimage"* ]]
60+
[[ "${output}" == *"test1"* ]]
61+
[[ "${output}" == *"test2"* ]]
6062

6163
temp_file_name=$(mktemp)
6264

63-
docker_swarm save busybox testimage > $temp_file_name
65+
# do not support save images which are on multi machine
66+
run docker_swarm save busybox test1 test2 > $temp_file_name
67+
[ "$status" -ne 0 ]
68+
[[ "${output}" == *"Not found an engine which has all images"* ]]
69+
70+
# save images which are on same machine
71+
docker_swarm save busybox test1 > $temp_file_name
6472

6573
# saved image file exists, not empty and is tar file
6674
[ -s $temp_file_name ]
6775
run file $temp_file_name
6876
[ "$status" -eq 0 ]
6977
[[ "${output}" == *"tar archive"* ]]
7078

79+
# load image on node-3
80+
docker -H ${HOSTS[2]} load < $temp_file_name
81+
# check image
82+
run docker -H ${HOSTS[2]} images
83+
[ "$status" -eq 0 ]
84+
[[ "${output}" == *"busybox"* ]]
85+
[[ "${output}" == *"test1"* ]]
86+
7187
rm -f $temp_file_name
7288
}

0 commit comments

Comments
 (0)