This fix migrates export tests in integration-cli to api tests.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -9,25 +9,8 @@ import ( |
| 9 | 9 |
"github.com/gotestyourself/gotestyourself/icmd" |
| 10 | 10 |
) |
| 11 | 11 |
|
| 12 |
-// export an image and try to import it into a new one |
|
| 13 |
-func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
|
|
| 14 |
- testRequires(c, DaemonIsLinux) |
|
| 15 |
- containerID := "testexportcontainerandimportimage" |
|
| 16 |
- |
|
| 17 |
- dockerCmd(c, "run", "--name", containerID, "busybox", "true") |
|
| 18 |
- |
|
| 19 |
- out, _ := dockerCmd(c, "export", containerID) |
|
| 20 |
- |
|
| 21 |
- result := icmd.RunCmd(icmd.Cmd{
|
|
| 22 |
- Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"},
|
|
| 23 |
- Stdin: strings.NewReader(out), |
|
| 24 |
- }) |
|
| 25 |
- result.Assert(c, icmd.Success) |
|
| 26 |
- |
|
| 27 |
- cleanedImageID := strings.TrimSpace(result.Combined()) |
|
| 28 |
- c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
|
|
| 29 |
-} |
|
| 30 |
- |
|
| 12 |
+// TODO: Move this test to docker/cli, as it is essentially the same test |
|
| 13 |
+// as TestExportContainerAndImportImage except output to a file. |
|
| 31 | 14 |
// Used to test output flag in the export command |
| 32 | 15 |
func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
|
| 33 | 16 |
testRequires(c, DaemonIsLinux) |
| 34 | 17 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,53 @@ |
| 0 |
+package container // import "github.com/docker/docker/integration/container" |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ "encoding/json" |
|
| 5 |
+ "testing" |
|
| 6 |
+ "time" |
|
| 7 |
+ |
|
| 8 |
+ "github.com/docker/docker/api/types" |
|
| 9 |
+ "github.com/docker/docker/api/types/filters" |
|
| 10 |
+ "github.com/docker/docker/integration/internal/container" |
|
| 11 |
+ "github.com/docker/docker/integration/internal/request" |
|
| 12 |
+ "github.com/docker/docker/pkg/jsonmessage" |
|
| 13 |
+ "github.com/gotestyourself/gotestyourself/poll" |
|
| 14 |
+ "github.com/gotestyourself/gotestyourself/skip" |
|
| 15 |
+ "github.com/stretchr/testify/assert" |
|
| 16 |
+ "github.com/stretchr/testify/require" |
|
| 17 |
+) |
|
| 18 |
+ |
|
| 19 |
+// export an image and try to import it into a new one |
|
| 20 |
+func TestExportContainerAndImportImage(t *testing.T) {
|
|
| 21 |
+ skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
|
| 22 |
+ |
|
| 23 |
+ defer setupTest(t)() |
|
| 24 |
+ client := request.NewAPIClient(t) |
|
| 25 |
+ ctx := context.Background() |
|
| 26 |
+ |
|
| 27 |
+ cID := container.Run(t, ctx, client, container.WithCmd("true"))
|
|
| 28 |
+ poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond)) |
|
| 29 |
+ |
|
| 30 |
+ reference := "repo/testexp:v1" |
|
| 31 |
+ exportResp, err := client.ContainerExport(ctx, cID) |
|
| 32 |
+ require.NoError(t, err) |
|
| 33 |
+ importResp, err := client.ImageImport(ctx, types.ImageImportSource{
|
|
| 34 |
+ Source: exportResp, |
|
| 35 |
+ SourceName: "-", |
|
| 36 |
+ }, reference, types.ImageImportOptions{})
|
|
| 37 |
+ require.NoError(t, err) |
|
| 38 |
+ |
|
| 39 |
+ // If the import is successfully, then the message output should contain |
|
| 40 |
+ // the image ID and match with the output from `docker images`. |
|
| 41 |
+ |
|
| 42 |
+ dec := json.NewDecoder(importResp) |
|
| 43 |
+ var jm jsonmessage.JSONMessage |
|
| 44 |
+ err = dec.Decode(&jm) |
|
| 45 |
+ require.NoError(t, err) |
|
| 46 |
+ |
|
| 47 |
+ images, err := client.ImageList(ctx, types.ImageListOptions{
|
|
| 48 |
+ Filters: filters.NewArgs(filters.Arg("reference", reference)),
|
|
| 49 |
+ }) |
|
| 50 |
+ require.NoError(t, err) |
|
| 51 |
+ assert.Equal(t, jm.Status, images[0].ID) |
|
| 52 |
+} |