(t *testing.T)
| 18 | func (notFound) NotFound() {} |
| 19 | |
| 20 | func TestValidateExternalNetworks(t *testing.T) { |
| 21 | testcases := []struct { |
| 22 | inspectResponse client.NetworkInspectResult |
| 23 | inspectError error |
| 24 | expectedMsg string |
| 25 | network string |
| 26 | }{ |
| 27 | { |
| 28 | inspectError: notFound{}, |
| 29 | expectedMsg: "could not be found. You need to create a swarm-scoped network", |
| 30 | }, |
| 31 | { |
| 32 | inspectError: errors.New("unexpected"), |
| 33 | expectedMsg: "unexpected", |
| 34 | }, |
| 35 | // FIXME(vdemeester) that doesn't work under windows, the check needs to be smarter |
| 36 | /* |
| 37 | { |
| 38 | inspectError: errors.New("host net does not exist on swarm classic"), |
| 39 | network: "host", |
| 40 | }, |
| 41 | */ |
| 42 | { |
| 43 | network: "user", |
| 44 | expectedMsg: "is not in the right scope", |
| 45 | }, |
| 46 | { |
| 47 | network: "user", |
| 48 | inspectResponse: client.NetworkInspectResult{ |
| 49 | Network: networktypes.Inspect{ |
| 50 | Network: networktypes.Network{ |
| 51 | Scope: "swarm", |
| 52 | }, |
| 53 | }, |
| 54 | }, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | for _, testcase := range testcases { |
| 59 | fakeAPIClient := &network.FakeClient{ |
| 60 | NetworkInspectFunc: func(_ context.Context, _ string, _ client.NetworkInspectOptions) (client.NetworkInspectResult, error) { |
| 61 | return testcase.inspectResponse, testcase.inspectError |
| 62 | }, |
| 63 | } |
| 64 | networks := []string{testcase.network} |
| 65 | err := validateExternalNetworks(context.Background(), fakeAPIClient, networks) |
| 66 | if testcase.expectedMsg == "" { |
| 67 | assert.NilError(t, err) |
| 68 | } else { |
| 69 | assert.ErrorContains(t, err, testcase.expectedMsg) |
| 70 | } |
| 71 | } |
| 72 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…