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

Function TestResolveNode

cli/command/idresolver/idresolver_test.go:72–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func TestResolveNode(t *testing.T) {
73 testCases := []struct {
74 nodeID string
75 nodeInspectFunc func(string) (client.NodeInspectResult, error)
76 expectedID string
77 }{
78 {
79 nodeID: "nodeID",
80 nodeInspectFunc: func(string) (client.NodeInspectResult, error) {
81 return client.NodeInspectResult{}, errors.New("error inspecting node")
82 },
83 expectedID: "nodeID",
84 },
85 {
86 nodeID: "nodeID",
87 nodeInspectFunc: func(string) (client.NodeInspectResult, error) {
88 return client.NodeInspectResult{
89 Node: *builders.Node(builders.NodeName("node-foo")),
90 }, nil
91 },
92 expectedID: "node-foo",
93 },
94 {
95 nodeID: "nodeID",
96 nodeInspectFunc: func(string) (client.NodeInspectResult, error) {
97 return client.NodeInspectResult{
98 Node: *builders.Node(builders.NodeName(""), builders.Hostname("node-hostname")),
99 }, nil
100 },
101 expectedID: "node-hostname",
102 },
103 }
104
105 ctx := context.Background()
106 for _, tc := range testCases {
107 apiClient := &fakeClient{
108 nodeInspectFunc: tc.nodeInspectFunc,
109 }
110 idResolver := New(apiClient, false)
111 id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID)
112
113 assert.NilError(t, err)
114 assert.Check(t, is.Equal(tc.expectedID, id))
115 }
116}
117
118func TestResolveService(t *testing.T) {
119 testCases := []struct {

Callers

nothing calls this directly

Calls 4

NodeMethod · 0.80
ResolveMethod · 0.80
NewFunction · 0.70
HostnameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…