| 70 | } |
| 71 | |
| 72 | func 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 | |
| 118 | func TestResolveService(t *testing.T) { |
| 119 | testCases := []struct { |