2023-03-28 19:12:30 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 19:12:30 +00:00
|
|
|
|
2017-10-11 12:51:21 +00:00
|
|
|
package join
|
2013-12-31 21:06:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2017-02-10 01:08:25 +00:00
|
|
|
|
|
|
|
"github.com/mitchellh/cli"
|
2021-10-28 21:44:38 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent"
|
2013-12-31 21:06:33 +00:00
|
|
|
)
|
|
|
|
|
2017-10-11 12:51:21 +00:00
|
|
|
func TestJoinCommand_noTabs(t *testing.T) {
|
2017-10-17 14:07:48 +00:00
|
|
|
t.Parallel()
|
2017-10-11 12:51:21 +00:00
|
|
|
if strings.ContainsRune(New(nil).Help(), '\t') {
|
2017-10-17 13:44:20 +00:00
|
|
|
t.Fatal("help has tabs")
|
2017-02-08 22:14:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-15 15:51:14 +00:00
|
|
|
func TestJoinCommandJoin_LAN(t *testing.T) {
|
2020-12-07 18:42:55 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("too slow for testing.Short")
|
|
|
|
}
|
|
|
|
|
2017-10-17 14:07:48 +00:00
|
|
|
t.Parallel()
|
2020-03-31 19:59:56 +00:00
|
|
|
a1 := agent.NewTestAgent(t, ``)
|
|
|
|
a2 := agent.NewTestAgent(t, ``)
|
2013-12-31 21:06:33 +00:00
|
|
|
defer a1.Shutdown()
|
|
|
|
defer a2.Shutdown()
|
|
|
|
|
2017-10-11 12:51:21 +00:00
|
|
|
ui := cli.NewMockUi()
|
|
|
|
cmd := New(ui)
|
2013-12-31 21:06:33 +00:00
|
|
|
args := []string{
|
2017-05-22 11:59:36 +00:00
|
|
|
"-http-addr=" + a1.HTTPAddr(),
|
2017-09-25 18:40:42 +00:00
|
|
|
a2.Config.SerfBindAddrLAN.String(),
|
2013-12-31 21:06:33 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 12:51:21 +00:00
|
|
|
code := cmd.Run(args)
|
2013-12-31 21:06:33 +00:00
|
|
|
if code != 0 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2021-10-26 20:08:55 +00:00
|
|
|
if len(a1.LANMembersInAgentPartition()) != 2 {
|
|
|
|
t.Fatalf("bad: %#v", a1.LANMembersInAgentPartition())
|
2013-12-31 21:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 12:04:51 +00:00
|
|
|
func TestJoinCommand_wan(t *testing.T) {
|
2020-12-07 18:42:55 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("too slow for testing.Short")
|
|
|
|
}
|
|
|
|
|
2017-10-17 14:07:48 +00:00
|
|
|
t.Parallel()
|
2020-03-31 19:59:56 +00:00
|
|
|
a1 := agent.NewTestAgent(t, ``)
|
|
|
|
a2 := agent.NewTestAgent(t, ``)
|
2013-12-31 21:06:33 +00:00
|
|
|
defer a1.Shutdown()
|
|
|
|
defer a2.Shutdown()
|
|
|
|
|
2017-10-11 12:51:21 +00:00
|
|
|
ui := cli.NewMockUi()
|
|
|
|
cmd := New(ui)
|
2013-12-31 21:06:33 +00:00
|
|
|
args := []string{
|
2017-05-22 11:59:36 +00:00
|
|
|
"-http-addr=" + a1.HTTPAddr(),
|
2013-12-31 21:06:33 +00:00
|
|
|
"-wan",
|
2017-09-25 18:40:42 +00:00
|
|
|
a2.Config.SerfBindAddrWAN.String(),
|
2013-12-31 21:06:33 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 12:51:21 +00:00
|
|
|
code := cmd.Run(args)
|
2013-12-31 21:06:33 +00:00
|
|
|
if code != 0 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:59:36 +00:00
|
|
|
if len(a1.WANMembers()) != 2 {
|
|
|
|
t.Fatalf("bad: %#v", a1.WANMembers())
|
2013-12-31 21:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 12:04:51 +00:00
|
|
|
func TestJoinCommand_noAddrs(t *testing.T) {
|
2017-10-17 14:07:48 +00:00
|
|
|
t.Parallel()
|
2017-10-11 12:51:21 +00:00
|
|
|
ui := cli.NewMockUi()
|
|
|
|
cmd := New(ui)
|
2017-02-08 22:14:02 +00:00
|
|
|
args := []string{"-http-addr=foo"}
|
2013-12-31 21:06:33 +00:00
|
|
|
|
2017-10-11 12:51:21 +00:00
|
|
|
code := cmd.Run(args)
|
2013-12-31 21:06:33 +00:00
|
|
|
if code != 1 {
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(ui.ErrorWriter.String(), "one address") {
|
|
|
|
t.Fatalf("bad: %#v", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
}
|