tests: do not return error from testagent shutdown (#15595)
This commit is contained in:
parent
3fd9fbeece
commit
83f9fc9db4
|
@ -19,7 +19,7 @@ func TestACLAuthMethodDeleteCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestACLAuthMethodInfoCommand(t *testing.T) {
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestACLAuthMethodListCommand(t *testing.T) {
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestACLBootstrapCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
must.Nil(t, srv.RootToken)
|
must.Nil(t, srv.RootToken)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func TestACLBootstrapCommand_ExistingBootstrapToken(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
must.NotNil(t, srv.RootToken)
|
must.NotNil(t, srv.RootToken)
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func TestACLBootstrapCommand_NonACLServer(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &ACLBootstrapCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &ACLBootstrapCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
@ -100,7 +100,7 @@ func TestACLBootstrapCommand_WithOperatorFileBootstrapToken(t *testing.T) {
|
||||||
must.NoError(t, err)
|
must.NoError(t, err)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
must.Nil(t, srv.RootToken)
|
must.Nil(t, srv.RootToken)
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ func TestACLBootstrapCommand_WithBadOperatorFileBootstrapToken(t *testing.T) {
|
||||||
must.NoError(t, err)
|
must.NoError(t, err)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
must.Nil(t, srv.RootToken)
|
must.Nil(t, srv.RootToken)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestACLPolicyApplyCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestACLPolicyDeleteCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestACLPolicyInfoCommand(t *testing.T) {
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -20,8 +20,9 @@ func TestACLPolicyListCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
defer stopTestAgent(srv)
|
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestACLTokenCreateCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestACLTokenDeleteCommand_ViaEnvVariable(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestACLTokenInfoCommand_ViaEnvVar(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestACLTokenListCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestACLTokenSelfCommand_ViaEnvVar(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestACLTokenUpdateCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, config)
|
srv, _, url := testServer(t, true, config)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Bootstrap an initial ACL token
|
// Bootstrap an initial ACL token
|
||||||
token := srv.RootToken
|
token := srv.RootToken
|
||||||
|
|
|
@ -1302,9 +1302,7 @@ func TestHTTPServer_Limits_OK(t *testing.T) {
|
||||||
c.Limits.HTTPMaxConnsPerClient = tc.limit
|
c.Limits.HTTPMaxConnsPerClient = tc.limit
|
||||||
c.LogLevel = "ERROR"
|
c.LogLevel = "ERROR"
|
||||||
})
|
})
|
||||||
defer func() {
|
defer s.Shutdown()
|
||||||
require.NoError(t, s.Shutdown())
|
|
||||||
}()
|
|
||||||
|
|
||||||
assertTimeout(t, s, tc.assertTimeout, tc.timeout)
|
assertTimeout(t, s, tc.assertTimeout, tc.timeout)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/hashicorp/nomad/api"
|
"github.com/hashicorp/nomad/api"
|
||||||
client "github.com/hashicorp/nomad/client/config"
|
client "github.com/hashicorp/nomad/client/config"
|
||||||
"github.com/hashicorp/nomad/client/fingerprint"
|
"github.com/hashicorp/nomad/client/fingerprint"
|
||||||
|
"github.com/hashicorp/nomad/helper"
|
||||||
"github.com/hashicorp/nomad/helper/freeport"
|
"github.com/hashicorp/nomad/helper/freeport"
|
||||||
"github.com/hashicorp/nomad/helper/testlog"
|
"github.com/hashicorp/nomad/helper/testlog"
|
||||||
"github.com/hashicorp/nomad/nomad"
|
"github.com/hashicorp/nomad/nomad"
|
||||||
|
@ -261,9 +262,9 @@ func (a *TestAgent) start() (*Agent, error) {
|
||||||
|
|
||||||
// Shutdown stops the agent and removes the data directory if it is
|
// Shutdown stops the agent and removes the data directory if it is
|
||||||
// managed by the test agent.
|
// managed by the test agent.
|
||||||
func (a *TestAgent) Shutdown() error {
|
func (a *TestAgent) Shutdown() {
|
||||||
if a.shutdown {
|
if a == nil || a.shutdown {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
a.shutdown = true
|
a.shutdown = true
|
||||||
|
|
||||||
|
@ -271,7 +272,7 @@ func (a *TestAgent) Shutdown() error {
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if a.DataDir != "" {
|
if a.DataDir != "" {
|
||||||
os.RemoveAll(a.DataDir)
|
_ = os.RemoveAll(a.DataDir)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -286,11 +287,17 @@ func (a *TestAgent) Shutdown() error {
|
||||||
ch <- a.Agent.Shutdown()
|
ch <- a.Agent.Shutdown()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// one minute grace period on shutdown
|
||||||
|
timer, cancel := helper.NewSafeTimer(1 * time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-ch:
|
case err := <-ch:
|
||||||
return err
|
if err != nil {
|
||||||
case <-time.After(1 * time.Minute):
|
a.T.Fatalf("agent shutdown error: %v", err)
|
||||||
return fmt.Errorf("timed out while shutting down test agent")
|
}
|
||||||
|
case <-timer.C:
|
||||||
|
a.T.Fatal("agent shutdown timeout")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestAgentInfoCommand_Implements(t *testing.T) {
|
||||||
func TestAgentInfoCommand_Run(t *testing.T) {
|
func TestAgentInfoCommand_Run(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
|
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -28,7 +28,7 @@ func TestAgentInfoCommand_Run(t *testing.T) {
|
||||||
func TestAgentInfoCommand_Run_JSON(t *testing.T) {
|
func TestAgentInfoCommand_Run_JSON(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
|
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -43,7 +43,7 @@ func TestAgentInfoCommand_Run_JSON(t *testing.T) {
|
||||||
func TestAgentInfoCommand_Run_Gotemplate(t *testing.T) {
|
func TestAgentInfoCommand_Run_Gotemplate(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
|
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestMonitorCommand_Implements(t *testing.T) {
|
||||||
func TestMonitorCommand_Fails(t *testing.T) {
|
func TestMonitorCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &MonitorCommand{Meta: Meta{Ui: ui}}
|
cmd := &MonitorCommand{Meta: Meta{Ui: ui}}
|
||||||
|
|
|
@ -19,9 +19,7 @@ func TestAllocChecksCommand_Implements(t *testing.T) {
|
||||||
func TestAllocChecksCommand_Fails(t *testing.T) {
|
func TestAllocChecksCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
t.Cleanup(func() {
|
defer srv.Shutdown()
|
||||||
_ = srv.Shutdown()
|
|
||||||
})
|
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocChecksCommand{Meta: Meta{Ui: ui}}
|
cmd := &AllocChecksCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -63,7 +61,7 @@ func TestAllocChecksCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocChecksCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &AllocChecksCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
@ -85,7 +83,7 @@ func TestAllocChecksCommand_AutocompleteArgs(t *testing.T) {
|
||||||
func TestAllocChecksCommand_Run(t *testing.T) {
|
func TestAllocChecksCommand_Run(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// wait for nodes
|
// wait for nodes
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
|
@ -22,7 +22,7 @@ var _ cli.Command = &AllocExecCommand{}
|
||||||
func TestAllocExecCommand_Fails(t *testing.T) {
|
func TestAllocExecCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -142,7 +142,7 @@ func TestAllocExecCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocExecCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &AllocExecCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
@ -164,7 +164,7 @@ func TestAllocExecCommand_AutocompleteArgs(t *testing.T) {
|
||||||
func TestAllocExecCommand_Run(t *testing.T) {
|
func TestAllocExecCommand_Run(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Wait for a node to be ready
|
// Wait for a node to be ready
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestFSCommand_Implements(t *testing.T) {
|
||||||
func TestFSCommand_Fails(t *testing.T) {
|
func TestFSCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocFSCommand{Meta: Meta{Ui: ui}}
|
cmd := &AllocFSCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -90,7 +90,7 @@ func TestFSCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocFSCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &AllocFSCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
|
|
@ -11,15 +11,12 @@ import (
|
||||||
"github.com/shoenig/test/must"
|
"github.com/shoenig/test/must"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLogsCommand_Implements(t *testing.T) {
|
var _ cli.Command = (*AllocLogsCommand)(nil)
|
||||||
ci.Parallel(t)
|
|
||||||
var _ cli.Command = &AllocLogsCommand{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLogsCommand_Fails(t *testing.T) {
|
func TestLogsCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocLogsCommand{Meta: Meta{Ui: ui}}
|
cmd := &AllocLogsCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -72,7 +69,7 @@ func TestLogsCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocLogsCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &AllocLogsCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestAllocRestartCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocRestartCommand{Meta: Meta{Ui: ui}}
|
cmd := &AllocRestartCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -103,7 +103,7 @@ func TestAllocRestartCommand_Run(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Wait for a node to be ready
|
// Wait for a node to be ready
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
@ -141,7 +141,7 @@ func TestAllocRestartCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocRestartCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &AllocRestartCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestAllocSignalCommand_Implements(t *testing.T) {
|
||||||
func TestAllocSignalCommand_Fails(t *testing.T) {
|
func TestAllocSignalCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocSignalCommand{Meta: Meta{Ui: ui}}
|
cmd := &AllocSignalCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -74,7 +74,7 @@ func TestAllocSignalCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocSignalCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &AllocSignalCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
@ -98,7 +98,7 @@ func TestAllocSignalCommand_Run(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Wait for a node to be ready
|
// Wait for a node to be ready
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestAllocStatusCommand_Implements(t *testing.T) {
|
||||||
func TestAllocStatusCommand_Fails(t *testing.T) {
|
func TestAllocStatusCommand_Fails(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
|
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -86,7 +86,7 @@ func TestAllocStatusCommand_LifecycleInfo(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func TestAllocStatusCommand_LifecycleInfo(t *testing.T) {
|
||||||
func TestAllocStatusCommand_Run(t *testing.T) {
|
func TestAllocStatusCommand_Run(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ func TestAllocStatusCommand_Run(t *testing.T) {
|
||||||
func TestAllocStatusCommand_RescheduleInfo(t *testing.T) {
|
func TestAllocStatusCommand_RescheduleInfo(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ func TestAllocStatusCommand_RescheduleInfo(t *testing.T) {
|
||||||
func TestAllocStatusCommand_ScoreMetrics(t *testing.T) {
|
func TestAllocStatusCommand_ScoreMetrics(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
@ -320,7 +320,7 @@ func TestAllocStatusCommand_HostVolumes(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ func TestAllocStatusCommand_HostVolumes(t *testing.T) {
|
||||||
func TestAllocStatusCommand_CSIVolumes(t *testing.T) {
|
func TestAllocStatusCommand_CSIVolumes(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, true, nil)
|
srv, _, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ func TestAllocStatusCommand_CSIVolumes(t *testing.T) {
|
||||||
func TestAllocStatusCommand_NSD_Checks(t *testing.T) {
|
func TestAllocStatusCommand_NSD_Checks(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// wait for nodes
|
// wait for nodes
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
|
@ -8,14 +8,11 @@ import (
|
||||||
"github.com/shoenig/test/must"
|
"github.com/shoenig/test/must"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAllocStopCommand_Implements(t *testing.T) {
|
var _ cli.Command = (*AllocStopCommand)(nil)
|
||||||
ci.Parallel(t)
|
|
||||||
var _ cli.Command = &AllocStopCommand{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAllocStop_Fails(t *testing.T) {
|
func TestAllocStop_Fails(t *testing.T) {
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AllocStopCommand{Meta: Meta{Ui: ui}}
|
cmd := &AllocStopCommand{Meta: Meta{Ui: ui}}
|
||||||
|
@ -66,7 +63,7 @@ func TestAllocStop_Run(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
// Wait for a node to be ready
|
// Wait for a node to be ready
|
||||||
waitForNodes(t, client)
|
waitForNodes(t, client)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func TestAgentCheckCommand_ServerHealth(t *testing.T) {
|
func TestAgentCheckCommand_ServerHealth(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
srv, _, url := testServer(t, false, nil)
|
srv, _, url := testServer(t, false, nil)
|
||||||
defer stopTestAgent(srv)
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &AgentCheckCommand{Meta: Meta{Ui: ui}}
|
cmd := &AgentCheckCommand{Meta: Meta{Ui: ui}}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func testServer(t *testing.T, runClient bool, cb func(*agent.Config)) (*agent.Te
|
||||||
cb(config)
|
cb(config)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Cleanup(func() { _ = a.Shutdown() })
|
t.Cleanup(a.Shutdown)
|
||||||
|
|
||||||
c := a.Client()
|
c := a.Client()
|
||||||
return a, c, a.HTTPAddr()
|
return a, c, a.HTTPAddr()
|
||||||
|
@ -38,7 +38,7 @@ func testClient(t *testing.T, name string, cb func(*agent.Config)) (*agent.TestA
|
||||||
cb(config)
|
cb(config)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Cleanup(func() { _ = a.Shutdown() })
|
t.Cleanup(a.Shutdown)
|
||||||
|
|
||||||
c := a.Client()
|
c := a.Client()
|
||||||
t.Logf("Waiting for client %s to join server(s) %s", name, a.GetConfig().Client.Servers)
|
t.Logf("Waiting for client %s to join server(s) %s", name, a.GetConfig().Client.Servers)
|
||||||
|
@ -195,10 +195,6 @@ func getAllocFromJob(t *testing.T, client *api.Client, jobID string) string {
|
||||||
return allocID
|
return allocID
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopTestAgent(a *agent.TestAgent) {
|
|
||||||
_ = a.Shutdown()
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTempFile(t *testing.T, name string) (string, func()) {
|
func getTempFile(t *testing.T, name string) (string, func()) {
|
||||||
f, err := os.CreateTemp("", name)
|
f, err := os.CreateTemp("", name)
|
||||||
must.NoError(t, err)
|
must.NoError(t, err)
|
||||||
|
|
|
@ -65,9 +65,7 @@ func TestVarGetCommand(t *testing.T) {
|
||||||
|
|
||||||
// Create a server
|
// Create a server
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
t.Cleanup(func() {
|
defer srv.Shutdown()
|
||||||
srv.Shutdown()
|
|
||||||
})
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -111,7 +109,7 @@ func TestVarGetCommand(t *testing.T) {
|
||||||
_, err = client.Namespaces().Register(&api.Namespace{Name: testNS}, nil)
|
_, err = client.Namespaces().Register(&api.Namespace{Name: testNS}, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
client.Namespaces().Delete(testNS, nil)
|
_, _ = client.Namespaces().Delete(testNS, nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create a var to get
|
// Create a var to get
|
||||||
|
@ -165,8 +163,6 @@ func TestVarGetCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Run("Autocomplete", func(t *testing.T) {
|
t.Run("Autocomplete", func(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
_, client, url, shutdownFn := testAPIClient(t)
|
|
||||||
defer shutdownFn()
|
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &VarGetCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &VarGetCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
@ -175,14 +171,18 @@ func TestVarGetCommand(t *testing.T) {
|
||||||
testNS := strings.Map(validNS, t.Name())
|
testNS := strings.Map(validNS, t.Name())
|
||||||
_, err := client.Namespaces().Register(&api.Namespace{Name: testNS}, nil)
|
_, err := client.Namespaces().Register(&api.Namespace{Name: testNS}, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() { client.Namespaces().Delete(testNS, nil) })
|
t.Cleanup(func() {
|
||||||
|
_, _ = client.Namespaces().Delete(testNS, nil)
|
||||||
|
})
|
||||||
|
|
||||||
sv := testVariable()
|
sv := testVariable()
|
||||||
sv.Path = "special/variable"
|
sv.Path = "special/variable"
|
||||||
sv.Namespace = testNS
|
sv.Namespace = testNS
|
||||||
sv, _, err = client.Variables().Create(sv, nil)
|
sv, _, err = client.Variables().Create(sv, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() { client.Variables().Delete(sv.Path, nil) })
|
t.Cleanup(func() {
|
||||||
|
_, _ = client.Variables().Delete(sv.Path, nil)
|
||||||
|
})
|
||||||
|
|
||||||
args := complete.Args{Last: "s"}
|
args := complete.Args{Last: "s"}
|
||||||
predictor := cmd.AutocompleteArgs()
|
predictor := cmd.AutocompleteArgs()
|
||||||
|
|
|
@ -64,9 +64,7 @@ func TestVarPurgeCommand_Online(t *testing.T) {
|
||||||
|
|
||||||
// Create a server
|
// Create a server
|
||||||
srv, client, url := testServer(t, true, nil)
|
srv, client, url := testServer(t, true, nil)
|
||||||
t.Cleanup(func() {
|
defer srv.Shutdown()
|
||||||
srv.Shutdown()
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("unchecked", func(t *testing.T) {
|
t.Run("unchecked", func(t *testing.T) {
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
|
|
|
@ -103,8 +103,8 @@ func TestVarPutCommand_GoodJson(t *testing.T) {
|
||||||
|
|
||||||
func TestVarPutCommand_AutocompleteArgs(t *testing.T) {
|
func TestVarPutCommand_AutocompleteArgs(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
_, client, url, shutdownFn := testAPIClient(t)
|
srv, client, url := testServer(t, true, nil)
|
||||||
defer shutdownFn()
|
defer srv.Shutdown()
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := &VarPutCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
cmd := &VarPutCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/nomad/api"
|
"github.com/hashicorp/nomad/api"
|
||||||
"github.com/hashicorp/nomad/command/agent"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// testVariable returns a test variable spec
|
// testVariable returns a test variable spec
|
||||||
|
@ -18,9 +15,3 @@ func testVariable() *api.Variable {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAPIClient(t *testing.T) (srv *agent.TestAgent, client *api.Client, url string, shutdownFn func() error) {
|
|
||||||
srv, client, url = testServer(t, true, nil)
|
|
||||||
shutdownFn = srv.Shutdown
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue