github.com/marwan-at-work/consul@v1.4.5/command/join/join_test.go (about) 1 package join 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/consul/agent" 8 "github.com/mitchellh/cli" 9 ) 10 11 func TestJoinCommand_noTabs(t *testing.T) { 12 t.Parallel() 13 if strings.ContainsRune(New(nil).Help(), '\t') { 14 t.Fatal("help has tabs") 15 } 16 } 17 18 func TestJoinCommandJoin_lan(t *testing.T) { 19 t.Parallel() 20 a1 := agent.NewTestAgent(t, t.Name(), ``) 21 a2 := agent.NewTestAgent(t, t.Name(), ``) 22 defer a1.Shutdown() 23 defer a2.Shutdown() 24 25 ui := cli.NewMockUi() 26 cmd := New(ui) 27 args := []string{ 28 "-http-addr=" + a1.HTTPAddr(), 29 a2.Config.SerfBindAddrLAN.String(), 30 } 31 32 code := cmd.Run(args) 33 if code != 0 { 34 t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) 35 } 36 37 if len(a1.LANMembers()) != 2 { 38 t.Fatalf("bad: %#v", a1.LANMembers()) 39 } 40 } 41 42 func TestJoinCommand_wan(t *testing.T) { 43 t.Parallel() 44 a1 := agent.NewTestAgent(t, t.Name(), ``) 45 a2 := agent.NewTestAgent(t, t.Name(), ``) 46 defer a1.Shutdown() 47 defer a2.Shutdown() 48 49 ui := cli.NewMockUi() 50 cmd := New(ui) 51 args := []string{ 52 "-http-addr=" + a1.HTTPAddr(), 53 "-wan", 54 a2.Config.SerfBindAddrWAN.String(), 55 } 56 57 code := cmd.Run(args) 58 if code != 0 { 59 t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) 60 } 61 62 if len(a1.WANMembers()) != 2 { 63 t.Fatalf("bad: %#v", a1.WANMembers()) 64 } 65 } 66 67 func TestJoinCommand_noAddrs(t *testing.T) { 68 t.Parallel() 69 ui := cli.NewMockUi() 70 cmd := New(ui) 71 args := []string{"-http-addr=foo"} 72 73 code := cmd.Run(args) 74 if code != 1 { 75 t.Fatalf("bad: %d", code) 76 } 77 78 if !strings.Contains(ui.ErrorWriter.String(), "one address") { 79 t.Fatalf("bad: %#v", ui.ErrorWriter.String()) 80 } 81 }