|
|
|
@ -43,6 +43,7 @@ func Test_SingleJoinOK(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
joiner := NewJoiner("127.0.0.1", numAttempts, attemptInterval, nil)
|
|
|
|
|
|
|
|
|
|
// Ensure joining with protocol prefix works.
|
|
|
|
|
j, err := joiner.Do([]string{ts.URL}, "id0", "127.0.0.1:9090", false)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
@ -60,6 +61,25 @@ func Test_SingleJoinOK(t *testing.T) {
|
|
|
|
|
if got, exp := body["voter"].(bool), false; got != exp {
|
|
|
|
|
t.Fatalf("wrong voter state supplied, exp %v, got %v", exp, got)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure joining without protocol prefix works.
|
|
|
|
|
j, err = joiner.Do([]string{ts.Listener.Addr().String()}, "id0", "127.0.0.1:9090", false)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if j != ts.URL+"/join" {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", j, ts.URL)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if got, exp := body["id"].(string), "id0"; got != exp {
|
|
|
|
|
t.Fatalf("wrong node ID supplied, exp %s, got %s", exp, got)
|
|
|
|
|
}
|
|
|
|
|
if got, exp := body["addr"].(string), "127.0.0.1:9090"; got != exp {
|
|
|
|
|
t.Fatalf("wrong address supplied, exp %s, got %s", exp, got)
|
|
|
|
|
}
|
|
|
|
|
if got, exp := body["voter"].(bool), false; got != exp {
|
|
|
|
|
t.Fatalf("wrong voter state supplied, exp %v, got %v", exp, got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_SingleJoinHTTPSOK(t *testing.T) {
|
|
|
|
@ -95,6 +115,7 @@ func Test_SingleJoinHTTPSOK(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
joiner := NewJoiner("127.0.0.1", numAttempts, attemptInterval, tlsConfig)
|
|
|
|
|
|
|
|
|
|
// Ensure joining with protocol prefix works.
|
|
|
|
|
j, err := joiner.Do([]string{ts.URL}, "id0", "127.0.0.1:9090", false)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
@ -112,6 +133,25 @@ func Test_SingleJoinHTTPSOK(t *testing.T) {
|
|
|
|
|
if got, exp := body["voter"].(bool), false; got != exp {
|
|
|
|
|
t.Fatalf("wrong voter state supplied, exp %v, got %v", exp, got)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure joining without protocol prefix works.
|
|
|
|
|
j, err = joiner.Do([]string{ts.Listener.Addr().String()}, "id0", "127.0.0.1:9090", false)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if j != ts.URL+"/join" {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", j, ts.URL)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if got, exp := body["id"].(string), "id0"; got != exp {
|
|
|
|
|
t.Fatalf("wrong node ID supplied, exp %s, got %s", exp, got)
|
|
|
|
|
}
|
|
|
|
|
if got, exp := body["addr"].(string), "127.0.0.1:9090"; got != exp {
|
|
|
|
|
t.Fatalf("wrong address supplied, exp %s, got %s", exp, got)
|
|
|
|
|
}
|
|
|
|
|
if got, exp := body["voter"].(bool), false; got != exp {
|
|
|
|
|
t.Fatalf("wrong voter state supplied, exp %v, got %v", exp, got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_SingleJoinOKBasicAuth(t *testing.T) {
|
|
|
|
@ -200,6 +240,7 @@ func Test_DoubleJoinOK(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
joiner := NewJoiner("127.0.0.1", numAttempts, attemptInterval, nil)
|
|
|
|
|
|
|
|
|
|
// Ensure joining with protocol prefix works.
|
|
|
|
|
j, err := joiner.Do([]string{ts1.URL, ts2.URL}, "id0", "127.0.0.1:9090", true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
@ -207,6 +248,15 @@ func Test_DoubleJoinOK(t *testing.T) {
|
|
|
|
|
if j != ts1.URL+"/join" {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", j, ts1.URL)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure joining without protocol prefix works.
|
|
|
|
|
j, err = joiner.Do([]string{ts1.Listener.Addr().String(), ts2.Listener.Addr().String()}, "id0", "127.0.0.1:9090", true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if j != ts1.URL+"/join" {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", j, ts1.URL)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_DoubleJoinOKSecondNode(t *testing.T) {
|
|
|
|
@ -220,6 +270,7 @@ func Test_DoubleJoinOKSecondNode(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
joiner := NewJoiner("", numAttempts, attemptInterval, nil)
|
|
|
|
|
|
|
|
|
|
// Ensure joining with protocol prefix works.
|
|
|
|
|
j, err := joiner.Do([]string{ts1.URL, ts2.URL}, "id0", "127.0.0.1:9090", true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
@ -227,6 +278,15 @@ func Test_DoubleJoinOKSecondNode(t *testing.T) {
|
|
|
|
|
if j != ts2.URL+"/join" {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", j, ts2.URL)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure joining without protocol prefix works.
|
|
|
|
|
j, err = joiner.Do([]string{ts1.Listener.Addr().String(), ts2.Listener.Addr().String()}, "id0", "127.0.0.1:9090", true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if j != ts2.URL+"/join" {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", j, ts2.URL)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_DoubleJoinOKSecondNodeRedirect(t *testing.T) {
|
|
|
|
@ -242,6 +302,7 @@ func Test_DoubleJoinOKSecondNodeRedirect(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
joiner := NewJoiner("127.0.0.1", numAttempts, attemptInterval, nil)
|
|
|
|
|
|
|
|
|
|
// Ensure joining with protocol prefix works.
|
|
|
|
|
j, err := joiner.Do([]string{ts2.URL}, "id0", "127.0.0.1:9090", true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
@ -249,4 +310,13 @@ func Test_DoubleJoinOKSecondNodeRedirect(t *testing.T) {
|
|
|
|
|
if j != redirectAddr {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", redirectAddr, j)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure joining without protocol prefix works.
|
|
|
|
|
j, err = joiner.Do([]string{ts2.Listener.Addr().String()}, "id0", "127.0.0.1:9090", true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if j != redirectAddr {
|
|
|
|
|
t.Fatalf("node joined using wrong endpoint, exp: %s, got: %s", redirectAddr, j)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|