github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/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  	var _ cli.Command = &AgentInfoCommand{}
    12  }
    13  
    14  func TestAgentInfoCommand_Run(t *testing.T) {
    15  	srv, _, url := testServer(t, nil)
    16  	defer srv.Stop()
    17  
    18  	ui := new(cli.MockUi)
    19  	cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
    20  
    21  	code := cmd.Run([]string{"-address=" + url})
    22  	if code != 0 {
    23  		t.Fatalf("expected exit 0, got: %d", code)
    24  	}
    25  }
    26  
    27  func TestAgentInfoCommand_Fails(t *testing.T) {
    28  	ui := new(cli.MockUi)
    29  	cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
    30  
    31  	// Fails on misuse
    32  	if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 {
    33  		t.Fatalf("expected exit code 1, got: %d", code)
    34  	}
    35  	if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) {
    36  		t.Fatalf("expected help output, got: %s", out)
    37  	}
    38  	ui.ErrorWriter.Reset()
    39  
    40  	// Fails on connection failure
    41  	if code := cmd.Run([]string{"-address=nope"}); code != 1 {
    42  		t.Fatalf("expected exit code 1, got: %d", code)
    43  	}
    44  	if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying agent info") {
    45  		t.Fatalf("expected failed query error, got: %s", out)
    46  	}
    47  }