| 47 | } |
| 48 | |
| 49 | func TestResolveWithCache(t *testing.T) { |
| 50 | inspectCounter := 0 |
| 51 | apiClient := &fakeClient{ |
| 52 | nodeInspectFunc: func(string) (client.NodeInspectResult, error) { |
| 53 | inspectCounter++ |
| 54 | return client.NodeInspectResult{ |
| 55 | Node: *builders.Node(builders.NodeName("node-foo")), |
| 56 | }, nil |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | idResolver := New(apiClient, false) |
| 61 | |
| 62 | ctx := context.Background() |
| 63 | for range 2 { |
| 64 | id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID") |
| 65 | assert.NilError(t, err) |
| 66 | assert.Check(t, is.Equal("node-foo", id)) |
| 67 | } |
| 68 | |
| 69 | assert.Check(t, is.Equal(1, inspectCounter)) |
| 70 | } |
| 71 | |
| 72 | func TestResolveNode(t *testing.T) { |
| 73 | testCases := []struct { |