open-nomad/command/agent_info_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
1.8 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2015-09-11 18:10:20 +00:00
package command
import (
"testing"
"github.com/hashicorp/nomad/ci"
2015-09-11 18:10:20 +00:00
"github.com/mitchellh/cli"
"github.com/shoenig/test/must"
2015-09-11 18:10:20 +00:00
)
func TestAgentInfoCommand_Implements(t *testing.T) {
ci.Parallel(t)
2015-09-11 18:10:20 +00:00
var _ cli.Command = &AgentInfoCommand{}
}
func TestAgentInfoCommand_Run(t *testing.T) {
ci.Parallel(t)
2017-07-21 04:07:32 +00:00
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()
2015-09-12 21:50:05 +00:00
2020-10-05 14:07:41 +00:00
ui := cli.NewMockUi()
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
2015-09-12 21:50:05 +00:00
code := cmd.Run([]string{"-address=" + url})
must.Zero(t, code)
2015-09-12 21:50:05 +00:00
}
func TestAgentInfoCommand_Run_JSON(t *testing.T) {
ci.Parallel(t)
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()
ui := cli.NewMockUi()
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
code := cmd.Run([]string{"-address=" + url, "-json"})
must.Zero(t, code)
out := ui.OutputWriter.String()
must.StrContains(t, out, `"config"`)
}
func TestAgentInfoCommand_Run_Gotemplate(t *testing.T) {
ci.Parallel(t)
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()
ui := cli.NewMockUi()
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
code := cmd.Run([]string{"-address=" + url, "-t", "{{.Stats.raft}}"})
must.Zero(t, code)
out := ui.OutputWriter.String()
must.StrContains(t, out, "last_log_index")
}
2015-09-12 21:50:05 +00:00
func TestAgentInfoCommand_Fails(t *testing.T) {
ci.Parallel(t)
2020-10-05 14:07:41 +00:00
ui := cli.NewMockUi()
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
2015-09-12 21:50:05 +00:00
// Fails on misuse
code := cmd.Run([]string{"some", "bad", "args"})
must.One(t, code)
out := ui.ErrorWriter.String()
must.StrContains(t, out, commandErrorText(cmd))
2015-09-12 23:36:44 +00:00
ui.ErrorWriter.Reset()
2015-09-12 21:50:05 +00:00
// Fails on connection failure
code = cmd.Run([]string{"-address=nope"})
must.One(t, code)
out = ui.ErrorWriter.String()
must.StrContains(t, out, "Error querying agent info")
2015-09-11 18:10:20 +00:00
}