| 89 | } |
| 90 | |
| 91 | func 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 | } |