MCPcopy Index your code
hub / github.com/docker/cli / TestSwarmUpdate

Function TestSwarmUpdate

cli/command/swarm/update_test.go:91–200  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestSwarmUpdate(t *testing.T) {
92 swarmInfo := builders.Swarm()
93 swarmInfo.ClusterInfo.TLSInfo.TrustRoot = "trust-root"
94
95 testCases := []struct {
96 name string
97 args []string
98 flags map[string]string
99 swarmInspectFunc func() (client.SwarmInspectResult, error)
100 swarmUpdateFunc func(client.SwarmUpdateOptions) (client.SwarmUpdateResult, error)
101 swarmGetUnlockKeyFunc func() (client.SwarmGetUnlockKeyResult, error)
102 }{
103 {
104 name: "noargs",
105 },
106 {
107 name: "all-flags-quiet",
108 flags: map[string]string{
109 flagTaskHistoryLimit: "10",
110 flagDispatcherHeartbeat: "10s",
111 flagCertExpiry: "20s",
112 flagExternalCA: "protocol=cfssl,url=https://example.com.",
113 flagMaxSnapshots: "10",
114 flagSnapshotInterval: "100",
115 flagAutolock: "true",
116 },
117 swarmInspectFunc: func() (client.SwarmInspectResult, error) {
118 return client.SwarmInspectResult{
119 Swarm: *swarmInfo,
120 }, nil
121 },
122 swarmUpdateFunc: func(options client.SwarmUpdateOptions) (client.SwarmUpdateResult, error) {
123 if *options.Spec.Orchestration.TaskHistoryRetentionLimit != 10 {
124 return client.SwarmUpdateResult{}, errors.New("historyLimit not correctly set")
125 }
126 heartbeatDuration, err := time.ParseDuration("10s")
127 if err != nil {
128 return client.SwarmUpdateResult{}, err
129 }
130 if options.Spec.Dispatcher.HeartbeatPeriod != heartbeatDuration {
131 return client.SwarmUpdateResult{}, errors.New("heartbeatPeriodLimit not correctly set")
132 }
133 certExpiryDuration, err := time.ParseDuration("20s")
134 if err != nil {
135 return client.SwarmUpdateResult{}, err
136 }
137 if options.Spec.CAConfig.NodeCertExpiry != certExpiryDuration {
138 return client.SwarmUpdateResult{}, errors.New("certExpiry not correctly set")
139 }
140 if len(options.Spec.CAConfig.ExternalCAs) != 1 || options.Spec.CAConfig.ExternalCAs[0].CACert != "trust-root" {
141 return client.SwarmUpdateResult{}, errors.New("externalCA not correctly set")
142 }
143 if *options.Spec.Raft.KeepOldSnapshots != 10 {
144 return client.SwarmUpdateResult{}, errors.New("keepOldSnapshots not correctly set")
145 }
146 if options.Spec.Raft.SnapshotInterval != 100 {
147 return client.SwarmUpdateResult{}, errors.New("snapshotInterval not correctly set")
148 }

Callers

nothing calls this directly

Calls 6

OutBufferMethod · 0.95
SetArgsMethod · 0.80
newUpdateCommandFunction · 0.70
StringMethod · 0.65
SetMethod · 0.45
SetOutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…