github.com/djenriquez/nomad-1@v0.8.1/command/operator_autopilot_set_test.go (about)

     1  package command
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/mitchellh/cli"
     9  )
    10  
    11  func TestOperator_Autopilot_SetConfig_Implements(t *testing.T) {
    12  	t.Parallel()
    13  	var _ cli.Command = &OperatorRaftListCommand{}
    14  }
    15  
    16  func TestOperatorAutopilotSetConfigCommand(t *testing.T) {
    17  	t.Parallel()
    18  	s, _, addr := testServer(t, false, nil)
    19  	defer s.Shutdown()
    20  
    21  	ui := new(cli.MockUi)
    22  	c := &OperatorAutopilotSetCommand{Meta: Meta{Ui: ui}}
    23  	args := []string{
    24  		"-address=" + addr,
    25  		"-cleanup-dead-servers=false",
    26  		"-max-trailing-logs=99",
    27  		"-last-contact-threshold=123ms",
    28  		"-server-stabilization-time=123ms",
    29  	}
    30  
    31  	code := c.Run(args)
    32  	if code != 0 {
    33  		t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
    34  	}
    35  	output := strings.TrimSpace(ui.OutputWriter.String())
    36  	if !strings.Contains(output, "Configuration updated") {
    37  		t.Fatalf("bad: %s", output)
    38  	}
    39  
    40  	client, err := c.Client()
    41  	if err != nil {
    42  		t.Fatal(err)
    43  	}
    44  
    45  	conf, _, err := client.Operator().AutopilotGetConfiguration(nil)
    46  	if err != nil {
    47  		t.Fatal(err)
    48  	}
    49  
    50  	if conf.CleanupDeadServers {
    51  		t.Fatalf("bad: %#v", conf)
    52  	}
    53  	if conf.MaxTrailingLogs != 99 {
    54  		t.Fatalf("bad: %#v", conf)
    55  	}
    56  	if conf.LastContactThreshold != 123*time.Millisecond {
    57  		t.Fatalf("bad: %#v", conf)
    58  	}
    59  	if conf.ServerStabilizationTime != 123*time.Millisecond {
    60  		t.Fatalf("bad: %#v", conf)
    61  	}
    62  }