Merge pull request #4723 from hashicorp/b-autopilot-cli

Fix autopilot set enable custom upgrades flag
This commit is contained in:
Alex Dadgar 2018-09-25 13:53:52 -07:00 committed by GitHub
commit c75dc3d1e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 25 deletions

View file

@ -75,7 +75,7 @@ func (c *OperatorAutopilotSetCommand) Run(args []string) int {
cleanupDeadServers.Merge(&conf.CleanupDeadServers) cleanupDeadServers.Merge(&conf.CleanupDeadServers)
enableRedundancyZones.Merge(&conf.EnableRedundancyZones) enableRedundancyZones.Merge(&conf.EnableRedundancyZones)
disableUpgradeMigration.Merge(&conf.DisableUpgradeMigration) disableUpgradeMigration.Merge(&conf.DisableUpgradeMigration)
enableRedundancyZones.Merge(&conf.EnableCustomUpgrades) enableCustomUpgrades.Merge(&conf.EnableCustomUpgrades)
trailing := uint(conf.MaxTrailingLogs) trailing := uint(conf.MaxTrailingLogs)
maxTrailingLogs.Merge(&trailing) maxTrailingLogs.Merge(&trailing)

View file

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
"github.com/stretchr/testify/require"
) )
func TestOperator_Autopilot_SetConfig_Implements(t *testing.T) { func TestOperator_Autopilot_SetConfig_Implements(t *testing.T) {
@ -15,6 +16,7 @@ func TestOperator_Autopilot_SetConfig_Implements(t *testing.T) {
func TestOperatorAutopilotSetConfigCommand(t *testing.T) { func TestOperatorAutopilotSetConfigCommand(t *testing.T) {
t.Parallel() t.Parallel()
require := require.New(t)
s, _, addr := testServer(t, false, nil) s, _, addr := testServer(t, false, nil)
defer s.Shutdown() defer s.Shutdown()
@ -26,37 +28,27 @@ func TestOperatorAutopilotSetConfigCommand(t *testing.T) {
"-max-trailing-logs=99", "-max-trailing-logs=99",
"-last-contact-threshold=123ms", "-last-contact-threshold=123ms",
"-server-stabilization-time=123ms", "-server-stabilization-time=123ms",
"-enable-redundancy-zones=true",
"-disable-upgrade-migration=true",
"-enable-custom-upgrades=true",
} }
code := c.Run(args) code := c.Run(args)
if code != 0 { require.EqualValues(0, code)
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
output := strings.TrimSpace(ui.OutputWriter.String()) output := strings.TrimSpace(ui.OutputWriter.String())
if !strings.Contains(output, "Configuration updated") { require.Contains(output, "Configuration updated")
t.Fatalf("bad: %s", output)
}
client, err := c.Client() client, err := c.Client()
if err != nil { require.NoError(err)
t.Fatal(err)
}
conf, _, err := client.Operator().AutopilotGetConfiguration(nil) conf, _, err := client.Operator().AutopilotGetConfiguration(nil)
if err != nil { require.NoError(err)
t.Fatal(err)
}
if conf.CleanupDeadServers { require.False(conf.CleanupDeadServers)
t.Fatalf("bad: %#v", conf) require.EqualValues(99, conf.MaxTrailingLogs)
} require.EqualValues(123*time.Millisecond, conf.LastContactThreshold)
if conf.MaxTrailingLogs != 99 { require.EqualValues(123*time.Millisecond, conf.ServerStabilizationTime)
t.Fatalf("bad: %#v", conf) require.True(conf.EnableRedundancyZones)
} require.True(conf.DisableUpgradeMigration)
if conf.LastContactThreshold != 123*time.Millisecond { require.True(conf.EnableCustomUpgrades)
t.Fatalf("bad: %#v", conf)
}
if conf.ServerStabilizationTime != 123*time.Millisecond {
t.Fatalf("bad: %#v", conf)
}
} }