|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + "os" |
| 6 | + "os/exec" |
| 7 | + |
| 8 | + "github.com/go-check/check" |
| 9 | + "github.com/docker/docker/pkg/integration/checker" |
| 10 | +) |
| 11 | + |
| 12 | +func (s *DockerSuite) TestCliRegionBasic(c *check.C) { |
| 13 | + printTestCaseName() |
| 14 | + defer printTestDuration(time.Now()) |
| 15 | + |
| 16 | + var ( |
| 17 | + defaultRegion = os.Getenv("REGION") |
| 18 | + anotherRegion = "" |
| 19 | + err error |
| 20 | + ) |
| 21 | + switch defaultRegion { |
| 22 | + case "": |
| 23 | + defaultRegion = "us-west-1" |
| 24 | + anotherRegion = "eu-central-1" |
| 25 | + case "us-west-1": |
| 26 | + anotherRegion = "eu-central-1" |
| 27 | + case "eu-central-1": |
| 28 | + anotherRegion = "us-west-1" |
| 29 | + } |
| 30 | + |
| 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 | + |
| 44 | + //////////////////////////////////////////// |
| 45 | + //pull image with default region |
| 46 | + cmd = exec.Command(dockerBinary, "pull", "busybox") |
| 47 | + out, _, err = runCommandWithOutput(cmd) |
| 48 | + if err != nil { |
| 49 | + c.Fatal(err, out) |
| 50 | + } |
| 51 | + c.Assert(out, checker.Contains, "Status: Downloaded newer image for busybox:latest") |
| 52 | + |
| 53 | + cmd = exec.Command(dockerBinary, "run", "busybox", "echo", "test123") |
| 54 | + out, _, err = runCommandWithOutput(cmd) |
| 55 | + if err != nil { |
| 56 | + c.Fatal(err, out) |
| 57 | + } |
| 58 | + c.Assert(out, checker.Not(checker.Contains), "Unable to find image 'busybox:latest' in the current region") |
| 59 | + c.Assert(out, checker.Contains, "test123") |
| 60 | + |
| 61 | + //////////////////////////////////////////// |
| 62 | + //image not exist in another region |
| 63 | + cmd = exec.Command(dockerBinary, "--region", anotherRegion, "images", "busybox") |
| 64 | + out, _, err = runCommandWithOutput(cmd) |
| 65 | + if err != nil { |
| 66 | + c.Fatal(err, out) |
| 67 | + } |
| 68 | + c.Assert(out, checker.Not(checker.Contains), "busybox") |
| 69 | + |
| 70 | + //////////////////////////////////////////// |
| 71 | + //pull image with specified region |
| 72 | + cmd = exec.Command(dockerBinary, "--region", anotherRegion, "pull", "ubuntu") |
| 73 | + out, _, err = runCommandWithOutput(cmd) |
| 74 | + if err != nil { |
| 75 | + c.Fatal(err, out) |
| 76 | + } |
| 77 | + c.Assert(out, checker.Contains, "Status: Downloaded newer image for ubuntu:latest") |
| 78 | + |
| 79 | + cmd = exec.Command(dockerBinary, "--region", anotherRegion, "run", "ubuntu", "echo", "test123") |
| 80 | + out, _, err = runCommandWithOutput(cmd) |
| 81 | + if err != nil { |
| 82 | + c.Fatal(err, out) |
| 83 | + } |
| 84 | + c.Assert(out, checker.Not(checker.Contains), "Unable to find image 'ubuntu:latest' in the current region") |
| 85 | + c.Assert(out, checker.Contains, "test123") |
| 86 | +} |
| 87 | + |
| 88 | +func (s *DockerSuite) TestCliRegionWithFullEntrypoint(c *check.C) { |
| 89 | + printTestCaseName() |
| 90 | + defer printTestDuration(time.Now()) |
| 91 | + cmd := exec.Command(dockerBinary, "--region", os.Getenv("DOCKER_HOST"), "pull", "busybox") |
| 92 | + out, _, err := runCommandWithOutput(cmd) |
| 93 | + if err != nil { |
| 94 | + c.Fatal(err, out) |
| 95 | + } |
| 96 | + c.Assert(out, checker.Contains, "Status: Downloaded newer image for busybox:latest") |
| 97 | +} |
0 commit comments