github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/container/export_test.go (about) 1 package container // import "github.com/demonoid81/moby/integration/container" 2 3 import ( 4 "context" 5 "encoding/json" 6 "testing" 7 "time" 8 9 "github.com/demonoid81/moby/api/types" 10 "github.com/demonoid81/moby/api/types/filters" 11 "github.com/demonoid81/moby/integration/internal/container" 12 "github.com/demonoid81/moby/pkg/jsonmessage" 13 "github.com/demonoid81/moby/testutil/daemon" 14 "gotest.tools/v3/assert" 15 is "gotest.tools/v3/assert/cmp" 16 "gotest.tools/v3/poll" 17 "gotest.tools/v3/skip" 18 ) 19 20 // export an image and try to import it into a new one 21 func TestExportContainerAndImportImage(t *testing.T) { 22 skip.If(t, testEnv.DaemonInfo.OSType == "windows") 23 24 defer setupTest(t)() 25 client := testEnv.APIClient() 26 ctx := context.Background() 27 28 cID := container.Run(ctx, t, client, container.WithCmd("true")) 29 poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond)) 30 31 reference := "repo/testexp:v1" 32 exportResp, err := client.ContainerExport(ctx, cID) 33 assert.NilError(t, err) 34 importResp, err := client.ImageImport(ctx, types.ImageImportSource{ 35 Source: exportResp, 36 SourceName: "-", 37 }, reference, types.ImageImportOptions{}) 38 assert.NilError(t, err) 39 40 // If the import is successfully, then the message output should contain 41 // the image ID and match with the output from `docker images`. 42 43 dec := json.NewDecoder(importResp) 44 var jm jsonmessage.JSONMessage 45 err = dec.Decode(&jm) 46 assert.NilError(t, err) 47 48 images, err := client.ImageList(ctx, types.ImageListOptions{ 49 Filters: filters.NewArgs(filters.Arg("reference", reference)), 50 }) 51 assert.NilError(t, err) 52 assert.Check(t, is.Equal(jm.Status, images[0].ID)) 53 } 54 55 // TestExportContainerAfterDaemonRestart checks that a container 56 // created before start of the currently running dockerd 57 // can be exported (as reported in #36561). To satisfy this 58 // condition, daemon restart is needed after container creation. 59 func TestExportContainerAfterDaemonRestart(t *testing.T) { 60 skip.If(t, testEnv.DaemonInfo.OSType == "windows") 61 skip.If(t, testEnv.IsRemoteDaemon) 62 63 d := daemon.New(t) 64 c := d.NewClientT(t) 65 66 d.StartWithBusybox(t) 67 defer d.Stop(t) 68 69 ctx := context.Background() 70 ctrID := container.Create(ctx, t, c) 71 72 d.Restart(t) 73 74 _, err := c.ContainerExport(ctx, ctrID) 75 assert.NilError(t, err) 76 }