github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/agent_info_test.go (about) 1 package command 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/ci" 7 "github.com/mitchellh/cli" 8 "github.com/shoenig/test/must" 9 ) 10 11 func TestAgentInfoCommand_Implements(t *testing.T) { 12 ci.Parallel(t) 13 var _ cli.Command = &AgentInfoCommand{} 14 } 15 16 func TestAgentInfoCommand_Run(t *testing.T) { 17 ci.Parallel(t) 18 srv, _, url := testServer(t, false, nil) 19 defer stopTestAgent(srv) 20 21 ui := cli.NewMockUi() 22 cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}} 23 24 code := cmd.Run([]string{"-address=" + url}) 25 must.Zero(t, code) 26 } 27 28 func TestAgentInfoCommand_Run_JSON(t *testing.T) { 29 ci.Parallel(t) 30 srv, _, url := testServer(t, false, nil) 31 defer stopTestAgent(srv) 32 33 ui := cli.NewMockUi() 34 cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}} 35 36 code := cmd.Run([]string{"-address=" + url, "-json"}) 37 must.Zero(t, code) 38 39 out := ui.OutputWriter.String() 40 must.StrContains(t, out, `"config"`) 41 } 42 43 func TestAgentInfoCommand_Run_Gotemplate(t *testing.T) { 44 ci.Parallel(t) 45 srv, _, url := testServer(t, false, nil) 46 defer stopTestAgent(srv) 47 48 ui := cli.NewMockUi() 49 cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}} 50 51 code := cmd.Run([]string{"-address=" + url, "-t", "{{.Stats.raft}}"}) 52 must.Zero(t, code) 53 54 out := ui.OutputWriter.String() 55 must.StrContains(t, out, "last_log_index") 56 } 57 58 func TestAgentInfoCommand_Fails(t *testing.T) { 59 ci.Parallel(t) 60 ui := cli.NewMockUi() 61 cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}} 62 63 // Fails on misuse 64 code := cmd.Run([]string{"some", "bad", "args"}) 65 must.One(t, code) 66 67 out := ui.ErrorWriter.String() 68 must.StrContains(t, out, commandErrorText(cmd)) 69 70 ui.ErrorWriter.Reset() 71 72 // Fails on connection failure 73 code = cmd.Run([]string{"-address=nope"}) 74 must.One(t, code) 75 76 out = ui.ErrorWriter.String() 77 must.StrContains(t, out, "Error querying agent info") 78 }