github.com/quite/nomad@v0.8.6/command/agent_info_test.go (about)

     1  package command
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/mitchellh/cli"
     8  )
     9  
    10  func TestAgentInfoCommand_Implements(t *testing.T) {
    11  	t.Parallel()
    12  	var _ cli.Command = &AgentInfoCommand{}
    13  }
    14  
    15  func TestAgentInfoCommand_Run(t *testing.T) {
    16  	t.Parallel()
    17  	srv, _, url := testServer(t, false, nil)
    18  	defer srv.Shutdown()
    19  
    20  	ui := new(cli.MockUi)
    21  	cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
    22  
    23  	code := cmd.Run([]string{"-address=" + url})
    24  	if code != 0 {
    25  		t.Fatalf("expected exit 0, got: %d", code)
    26  	}
    27  }
    28  
    29  func TestAgentInfoCommand_Fails(t *testing.T) {
    30  	t.Parallel()
    31  	ui := new(cli.MockUi)
    32  	cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
    33  
    34  	// Fails on misuse
    35  	if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 {
    36  		t.Fatalf("expected exit code 1, got: %d", code)
    37  	}
    38  	if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) {
    39  		t.Fatalf("expected help output, got: %s", out)
    40  	}
    41  	ui.ErrorWriter.Reset()
    42  
    43  	// Fails on connection failure
    44  	if code := cmd.Run([]string{"-address=nope"}); code != 1 {
    45  		t.Fatalf("expected exit code 1, got: %d", code)
    46  	}
    47  	if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying agent info") {
    48  		t.Fatalf("expected failed query error, got: %s", out)
    49  	}
    50  }