| 116 | } |
| 117 | |
| 118 | func TestResolveService(t *testing.T) { |
| 119 | testCases := []struct { |
| 120 | serviceID string |
| 121 | serviceInspectFunc func(string) (client.ServiceInspectResult, error) |
| 122 | expectedID string |
| 123 | }{ |
| 124 | { |
| 125 | serviceID: "serviceID", |
| 126 | serviceInspectFunc: func(string) (client.ServiceInspectResult, error) { |
| 127 | return client.ServiceInspectResult{}, errors.New("error inspecting service") |
| 128 | }, |
| 129 | expectedID: "serviceID", |
| 130 | }, |
| 131 | { |
| 132 | serviceID: "serviceID", |
| 133 | serviceInspectFunc: func(string) (client.ServiceInspectResult, error) { |
| 134 | return client.ServiceInspectResult{ |
| 135 | Service: *builders.Service(builders.ServiceName("service-foo")), |
| 136 | }, nil |
| 137 | }, |
| 138 | expectedID: "service-foo", |
| 139 | }, |
| 140 | } |
| 141 | |
| 142 | ctx := context.Background() |
| 143 | for _, tc := range testCases { |
| 144 | apiClient := &fakeClient{ |
| 145 | serviceInspectFunc: tc.serviceInspectFunc, |
| 146 | } |
| 147 | idResolver := New(apiClient, false) |
| 148 | id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID) |
| 149 | |
| 150 | assert.NilError(t, err) |
| 151 | assert.Check(t, is.Equal(tc.expectedID, id)) |
| 152 | } |
| 153 | } |