(t *testing.T)
| 142 | } |
| 143 | |
| 144 | func 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 | |
| 167 | func TestVolumeContextWriteJSONField(t *testing.T) { |
| 168 | volumes := []volume.Volume{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…