MCPcopy Index your code
hub / github.com/docker/cli / TestExportImportPipe

Function TestExportImportPipe

cli/command/context/export-import_test.go:48–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

46}
47
48func TestExportImportPipe(t *testing.T) {
49 cli := makeFakeCli(t)
50 createTestContext(t, cli, "test", map[string]any{
51 "MyCustomMetadata": t.Name(),
52 })
53 cli.ErrBuffer().Reset()
54 cli.OutBuffer().Reset()
55 assert.NilError(t, runExport(cli, "test", "-"))
56 assert.Equal(t, cli.ErrBuffer().String(), "")
57 cli.SetIn(streams.NewIn(io.NopCloser(bytes.NewBuffer(cli.OutBuffer().Bytes()))))
58 cli.OutBuffer().Reset()
59 cli.ErrBuffer().Reset()
60 assert.NilError(t, runImport(cli, "test2", "-"))
61 context1, err := cli.ContextStore().GetMetadata("test")
62 assert.NilError(t, err)
63 context2, err := cli.ContextStore().GetMetadata("test2")
64 assert.NilError(t, err)
65
66 assert.Check(t, is.DeepEqual(context1.Metadata, command.DockerContext{
67 Description: "description of test",
68 AdditionalFields: map[string]any{"MyCustomMetadata": t.Name()},
69 }))
70
71 assert.Check(t, is.DeepEqual(context1.Endpoints, context2.Endpoints))
72 assert.Check(t, is.DeepEqual(context1.Metadata, context2.Metadata))
73 assert.Check(t, is.Equal("test", context1.Name))
74 assert.Check(t, is.Equal("test2", context2.Name))
75
76 assert.Check(t, is.Equal("test2\n", cli.OutBuffer().String()))
77 assert.Check(t, is.Equal("Successfully imported context \"test2\"\n", cli.ErrBuffer().String()))
78}
79
80func TestExportExistingFile(t *testing.T) {
81 contextFile := filepath.Join(t.TempDir(), "exported")

Callers

nothing calls this directly

Calls 11

makeFakeCliFunction · 0.85
createTestContextFunction · 0.85
runExportFunction · 0.70
runImportFunction · 0.70
StringMethod · 0.65
SetInMethod · 0.65
GetMetadataMethod · 0.65
ContextStoreMethod · 0.65
NameMethod · 0.45
ErrBufferMethod · 0.45
OutBufferMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…