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