MCPcopy
hub / github.com/moby/moby / TestNetworkConnect

Function TestNetworkConnect

client/network_connect_test.go:67–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

65}
66
67func TestNetworkConnect(t *testing.T) {
68 const expectedURL = "/networks/network_id/connect"
69
70 client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) {
71 if err := assertRequest(req, http.MethodPost, expectedURL); err != nil {
72 return nil, err
73 }
74
75 var connect network.ConnectRequest
76 if err := json.NewDecoder(req.Body).Decode(&connect); err != nil {
77 return nil, err
78 }
79
80 if connect.Container != "container_id" {
81 return nil, fmt.Errorf("expected 'container_id', got %s", connect.Container)
82 }
83
84 if connect.EndpointConfig == nil {
85 return nil, fmt.Errorf("expected connect.EndpointConfig to be not nil, got %v", connect.EndpointConfig)
86 }
87
88 if connect.EndpointConfig.NetworkID != "NetworkID" {
89 return nil, fmt.Errorf("expected 'NetworkID', got %s", connect.EndpointConfig.NetworkID)
90 }
91
92 return mockResponse(http.StatusOK, nil, "")(req)
93 }))
94 assert.NilError(t, err)
95
96 _, err = client.NetworkConnect(t.Context(), "network_id", NetworkConnectOptions{
97 Container: "container_id",
98 EndpointConfig: &network.EndpointSettings{
99 NetworkID: "NetworkID",
100 },
101 })
102 assert.NilError(t, err)
103}

Callers

nothing calls this directly

Calls 8

WithMockClientFunction · 0.85
assertRequestFunction · 0.85
mockResponseFunction · 0.85
ErrorfMethod · 0.80
NewFunction · 0.70
DecodeMethod · 0.65
NetworkConnectMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…