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

Function TestNetworkContextWriteJSON

cli/command/network/formatter_test.go:196–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

194}
195
196func TestNetworkContextWriteJSON(t *testing.T) {
197 networks := []network.Summary{
198 {
199 Network: network.Network{
200 ID: "networkID1",
201 Name: "foobar_baz",
202 },
203 },
204 {
205 Network: network.Network{
206 ID: "networkID2",
207 Name: "foobar_bar",
208 },
209 },
210 }
211 expectedJSONs := []map[string]any{
212 {"Driver": "", "ID": "networkID1", "IPv4": "false", "IPv6": "false", "Internal": "false", "Labels": "", "Name": "foobar_baz", "Scope": "", "CreatedAt": "0001-01-01 00:00:00 +0000 UTC"},
213 {"Driver": "", "ID": "networkID2", "IPv4": "false", "IPv6": "false", "Internal": "false", "Labels": "", "Name": "foobar_bar", "Scope": "", "CreatedAt": "0001-01-01 00:00:00 +0000 UTC"},
214 }
215
216 out := bytes.NewBufferString("")
217 err := formatWrite(formatter.Context{Format: "{{json .}}", Output: out}, client.NetworkListResult{
218 Items: networks,
219 })
220 if err != nil {
221 t.Fatal(err)
222 }
223 for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") {
224 msg := fmt.Sprintf("Output: line %d: %s", i, line)
225 var m map[string]any
226 err := json.Unmarshal([]byte(line), &m)
227 assert.NilError(t, err, msg)
228 assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
229 }
230}
231
232func TestNetworkContextWriteJSONField(t *testing.T) {
233 networks := []network.Summary{

Callers

nothing calls this directly

Calls 2

formatWriteFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…