2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2016-04-10 08:45:10 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2016-04-10 08:45:10 +00:00
|
|
|
"github.com/mitchellh/cli"
|
2022-08-18 13:51:53 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2016-04-10 08:45:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAgentCheckCommand_ServerHealth(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2017-07-21 04:07:32 +00:00
|
|
|
srv, _, url := testServer(t, false, nil)
|
2022-12-21 14:23:58 +00:00
|
|
|
defer srv.Shutdown()
|
2016-04-10 08:45:10 +00:00
|
|
|
|
2020-10-05 14:07:41 +00:00
|
|
|
ui := cli.NewMockUi()
|
2016-04-10 08:45:10 +00:00
|
|
|
cmd := &AgentCheckCommand{Meta: Meta{Ui: ui}}
|
|
|
|
address := fmt.Sprintf("-address=%s", url)
|
|
|
|
|
|
|
|
code := cmd.Run([]string{address})
|
2022-08-18 13:51:53 +00:00
|
|
|
must.Eq(t, HealthPass, code)
|
2016-04-10 08:45:10 +00:00
|
|
|
|
|
|
|
minPeers := fmt.Sprintf("-min-peers=%v", 3)
|
|
|
|
code = cmd.Run([]string{address, minPeers})
|
2022-08-18 13:51:53 +00:00
|
|
|
must.Eq(t, HealthCritical, code)
|
2016-04-10 08:45:10 +00:00
|
|
|
}
|