MCPcopy Create free account
hub / github.com/docker/cli / TestConvertRestartPolicy

Function TestConvertRestartPolicy

cli/compose/convert/service_test.go:21–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func 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
69func strPtr(val string) *string {
70 return &val

Callers

nothing calls this directly

Calls 1

convertRestartPolicyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…