(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestConvertRestartPolicy(t *testing.T) { |
| 22 | attempts := uint64(4) |
| 23 | tests := []struct { |
| 24 | input string |
| 25 | expected *swarm.RestartPolicy |
| 26 | expError string |
| 27 | }{ |
| 28 | {}, |
| 29 | { |
| 30 | input: "no", |
| 31 | }, |
| 32 | { |
| 33 | input: "unknown", |
| 34 | expError: "invalid restart policy: unknown policy 'unknown'", |
| 35 | }, |
| 36 | { |
| 37 | input: "always", |
| 38 | expected: &swarm.RestartPolicy{ |
| 39 | Condition: swarm.RestartPolicyConditionAny, |
| 40 | }, |
| 41 | }, |
| 42 | { |
| 43 | input: "on-failure:4", |
| 44 | expected: &swarm.RestartPolicy{ |
| 45 | Condition: swarm.RestartPolicyConditionOnFailure, |
| 46 | MaxAttempts: &attempts, |
| 47 | }, |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | for _, tc := range tests { |
| 52 | name := tc.input |
| 53 | if name == "" { |
| 54 | name = "empty" |
| 55 | } |
| 56 | t.Run(name, func(t *testing.T) { |
| 57 | policy, err := convertRestartPolicy(tc.input, nil) |
| 58 | if tc.expError != "" { |
| 59 | assert.Check(t, is.ErrorContains(err, tc.expError)) |
| 60 | assert.Check(t, is.Nil(policy)) |
| 61 | return |
| 62 | } |
| 63 | assert.NilError(t, err) |
| 64 | assert.Check(t, is.DeepEqual(policy, tc.expected)) |
| 65 | }) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func strPtr(val string) *string { |
| 70 | return &val |
nothing calls this directly
no test coverage detected
searching dependent graphs…