docker-cli/cli/command/context/inspect_test.go
Sebastiaan van Stijn 2e9eff235d
cli/command/context: test inspecting context with custom metadata
The CLI does not currently expose options to add custom metadata to
contexts, but contexts support them.

- update test-utilities to allow setting custom metadata
- update the inspect test to verify that custom metadata is included
  when inspecting a context.
- update the import/export tests to verify that custom metadata
  is preserved.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-31 10:49:50 +02:00

26 lines
742 B
Go

package context
import (
"strings"
"testing"
"gotest.tools/v3/assert"
"gotest.tools/v3/golden"
)
func TestInspect(t *testing.T) {
cli := makeFakeCli(t)
createTestContext(t, cli, "current", map[string]any{
"MyCustomMetadata": "MyCustomMetadataValue",
})
cli.OutBuffer().Reset()
assert.NilError(t, runInspect(cli, inspectOptions{
refs: []string{"current"},
}))
expected := string(golden.Get(t, "inspect.golden"))
si := cli.ContextStore().GetStorageInfo("current")
expected = strings.Replace(expected, "<METADATA_PATH>", strings.ReplaceAll(si.MetadataPath, `\`, `\\`), 1)
expected = strings.Replace(expected, "<TLS_PATH>", strings.ReplaceAll(si.TLSPath, `\`, `\\`), 1)
assert.Equal(t, cli.OutBuffer().String(), expected)
}