MCPcopy
hub / github.com/moby/moby / TestNetworkQuery

Function TestNetworkQuery

daemon/libnetwork/libnetwork_linux_test.go:581–622  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

579}
580
581func TestNetworkQuery(t *testing.T) {
582 defer netnsutils.SetupTestOSContext(t)()
583 controller := newController(t)
584
585 // Create network 1 and add 2 endpoint: ep11, ep12
586 netOption := options.Generic{
587 netlabel.EnableIPv4: true,
588 netlabel.GenericData: map[string]string{
589 bridge.BridgeName: "network1",
590 },
591 }
592 net1, err := createTestNetwork(controller, bridgeNetType, "network1", netOption, nil, nil)
593 assert.NilError(t, err)
594 defer func() {
595 assert.Check(t, net1.Delete())
596 }()
597
598 ep11, err := net1.CreateEndpoint(context.Background(), "ep11")
599 assert.NilError(t, err)
600 defer func() {
601 assert.Check(t, ep11.Delete(context.Background(), false))
602 }()
603
604 ep12, err := net1.CreateEndpoint(context.Background(), "ep12")
605 assert.NilError(t, err)
606 defer func() {
607 assert.Check(t, ep12.Delete(context.Background(), false))
608 }()
609
610 e, err := net1.EndpointByName("ep11")
611 assert.NilError(t, err)
612 assert.Check(t, is.Equal(e, ep11), "EndpointByName() returned the wrong endpoint")
613
614 _, err = net1.EndpointByName("")
615 assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
616 assert.Check(t, is.ErrorContains(err, "invalid name:"))
617
618 e, err = net1.EndpointByName("IamNotAnEndpoint")
619 assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
620 assert.Check(t, is.Error(err, "endpoint IamNotAnEndpoint not found"))
621 assert.Check(t, is.Nil(e), "EndpointByName() returned endpoint on error")
622}
623
624const containerID = "valid_c"
625

Callers

nothing calls this directly

Calls 9

SetupTestOSContextFunction · 0.92
createTestNetworkFunction · 0.85
CheckMethod · 0.80
EndpointByNameMethod · 0.80
EqualMethod · 0.80
newControllerFunction · 0.70
DeleteMethod · 0.65
CreateEndpointMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…