Since `cirros.tar.gz` only existed to test `docker import`'s display and
presence in `docker events`, we can instead just use `docker export`
piped directly to `docker import` to achieve the same goal without
another external dependency besides `busybox` (which we already have).
While I was at it, I updated `TestImportDisplay` to also test that the
imported image actually runs successfully as well (so we're testing the
full import round-trip).
Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>
| ... | ... |
@@ -110,9 +110,6 @@ RUN gem install --no-rdoc --no-ri fpm --version 1.3.2 |
| 110 | 110 |
# Get the "busybox" image source so we can build locally instead of pulling |
| 111 | 111 |
RUN git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox |
| 112 | 112 |
|
| 113 |
-# Get the "cirros" image source so we can import it instead of fetching it during tests |
|
| 114 |
-RUN curl -sSL -o /cirros.tar.gz https://github.com/ewindisch/docker-cirros/raw/1cded459668e8b9dbf4ef976c94c05add9bbd8e9/cirros-0.3.0-x86_64-lxc.tar.gz |
|
| 115 |
- |
|
| 116 | 113 |
# Install registry |
| 117 | 114 |
ENV REGISTRY_COMMIT c448e0416925a9876d5576e412703c9b8b865e19 |
| 118 | 115 |
RUN set -x \ |
| ... | ... |
@@ -206,18 +206,18 @@ func TestEventsImagePull(t *testing.T) {
|
| 206 | 206 |
func TestEventsImageImport(t *testing.T) {
|
| 207 | 207 |
since := time.Now().Unix() |
| 208 | 208 |
|
| 209 |
- defer deleteImages("cirros")
|
|
| 210 |
- |
|
| 211 |
- server, err := fileServer(map[string]string{
|
|
| 212 |
- "/cirros.tar.gz": "/cirros.tar.gz", |
|
| 213 |
- }) |
|
| 209 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true") |
|
| 210 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 214 | 211 |
if err != nil {
|
| 215 |
- t.Fatal(err) |
|
| 212 |
+ t.Fatal("failed to create a container", out, err)
|
|
| 216 | 213 |
} |
| 217 |
- defer server.Close() |
|
| 218 |
- fileURL := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
|
|
| 219 |
- importCmd := exec.Command(dockerBinary, "import", fileURL, "cirros") |
|
| 220 |
- out, _, err := runCommandWithOutput(importCmd) |
|
| 214 |
+ cleanedContainerID := stripTrailingCharacters(out) |
|
| 215 |
+ defer deleteContainer(cleanedContainerID) |
|
| 216 |
+ |
|
| 217 |
+ out, _, err = runCommandPipelineWithOutput( |
|
| 218 |
+ exec.Command(dockerBinary, "export", cleanedContainerID), |
|
| 219 |
+ exec.Command(dockerBinary, "import", "-"), |
|
| 220 |
+ ) |
|
| 221 | 221 |
if err != nil {
|
| 222 | 222 |
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
| 223 | 223 |
} |
| ... | ... |
@@ -1,32 +1,43 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 5 | 4 |
"os/exec" |
| 6 | 5 |
"strings" |
| 7 | 6 |
"testing" |
| 8 | 7 |
) |
| 9 | 8 |
|
| 10 | 9 |
func TestImportDisplay(t *testing.T) {
|
| 11 |
- server, err := fileServer(map[string]string{
|
|
| 12 |
- "/cirros.tar.gz": "/cirros.tar.gz", |
|
| 13 |
- }) |
|
| 10 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true") |
|
| 11 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 14 | 12 |
if err != nil {
|
| 15 |
- t.Fatal(err) |
|
| 13 |
+ t.Fatal("failed to create a container", out, err)
|
|
| 16 | 14 |
} |
| 17 |
- defer server.Close() |
|
| 18 |
- fileURL := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
|
|
| 19 |
- importCmd := exec.Command(dockerBinary, "import", fileURL, "cirros") |
|
| 20 |
- out, _, err := runCommandWithOutput(importCmd) |
|
| 15 |
+ cleanedContainerID := stripTrailingCharacters(out) |
|
| 16 |
+ defer deleteContainer(cleanedContainerID) |
|
| 17 |
+ |
|
| 18 |
+ out, _, err = runCommandPipelineWithOutput( |
|
| 19 |
+ exec.Command(dockerBinary, "export", cleanedContainerID), |
|
| 20 |
+ exec.Command(dockerBinary, "import", "-"), |
|
| 21 |
+ ) |
|
| 21 | 22 |
if err != nil {
|
| 22 | 23 |
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
| 23 | 24 |
} |
| 24 | 25 |
|
| 25 |
- if n := strings.Count(out, "\n"); n != 2 {
|
|
| 26 |
- t.Fatalf("display is messed up: %d '\\n' instead of 2", n)
|
|
| 26 |
+ if n := strings.Count(out, "\n"); n != 1 {
|
|
| 27 |
+ t.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
|
| 27 | 28 |
} |
| 29 |
+ image := strings.TrimSpace(out) |
|
| 30 |
+ defer deleteImages(image) |
|
| 28 | 31 |
|
| 29 |
- deleteImages("cirros")
|
|
| 32 |
+ runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true") |
|
| 33 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 34 |
+ if err != nil {
|
|
| 35 |
+ t.Fatal("failed to create a container", out, err)
|
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ if out != "" {
|
|
| 39 |
+ t.Fatalf("command output should've been nothing, was %q", out)
|
|
| 40 |
+ } |
|
| 30 | 41 |
|
| 31 |
- logDone("import - cirros was imported and display is fine")
|
|
| 42 |
+ logDone("import - display is fine, imported image runs")
|
|
| 32 | 43 |
} |