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

Function TestVolumeContextWriteJSON

cli/command/formatter/volume_test.go:144–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestVolumeContextWriteJSON(t *testing.T) {
145 volumes := []volume.Volume{
146 {Driver: "foo", Name: "foobar_baz"},
147 {Driver: "bar", Name: "foobar_bar"},
148 }
149 expectedJSONs := []map[string]any{
150 {"Availability": "N/A", "Driver": "foo", "Group": "N/A", "Labels": "", "Links": "N/A", "Mountpoint": "", "Name": "foobar_baz", "Scope": "", "Size": "N/A", "Status": "N/A"},
151 {"Availability": "N/A", "Driver": "bar", "Group": "N/A", "Labels": "", "Links": "N/A", "Mountpoint": "", "Name": "foobar_bar", "Scope": "", "Size": "N/A", "Status": "N/A"},
152 }
153 out := bytes.NewBufferString("")
154 err := VolumeWrite(Context{Format: "{{json .}}", Output: out}, volumes)
155 if err != nil {
156 t.Fatal(err)
157 }
158 for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") {
159 msg := fmt.Sprintf("Output: line %d: %s", i, line)
160 var m map[string]any
161 err := json.Unmarshal([]byte(line), &m)
162 assert.NilError(t, err, msg)
163 assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
164 }
165}
166
167func TestVolumeContextWriteJSONField(t *testing.T) {
168 volumes := []volume.Volume{

Callers

nothing calls this directly

Calls 2

VolumeWriteFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…