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