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

Function TestNetworkContextWriteJSONField

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

Source from the content-addressed store, hash-verified

230}
231
232func TestNetworkContextWriteJSONField(t *testing.T) {
233 networks := []network.Summary{
234 {
235 Network: network.Network{
236 ID: "networkID1",
237 Name: "foobar_baz",
238 },
239 },
240 {
241 Network: network.Network{
242 ID: "networkID2",
243 Name: "foobar_bar",
244 },
245 },
246 }
247 out := bytes.NewBufferString("")
248 err := formatWrite(formatter.Context{Format: "{{json .ID}}", Output: out}, client.NetworkListResult{
249 Items: networks,
250 })
251 if err != nil {
252 t.Fatal(err)
253 }
254 for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") {
255 msg := fmt.Sprintf("Output: line %d: %s", i, line)
256 var s string
257 err := json.Unmarshal([]byte(line), &s)
258 assert.NilError(t, err, msg)
259 assert.Check(t, is.Equal(networks[i].ID, s), msg)
260 }
261}

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…