|
@@ -1,6 +1,7 @@
|
|
|
package etcdserver
|
|
package etcdserver
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "reflect"
|
|
|
"testing"
|
|
"testing"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -141,3 +142,62 @@ func TestClusterAddBad(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func TestClusterClientURLs(t *testing.T) {
|
|
|
|
|
+ tests := []struct {
|
|
|
|
|
+ mems []Member
|
|
|
|
|
+ wurls []string
|
|
|
|
|
+ }{
|
|
|
|
|
+ // single peer with a single address
|
|
|
|
|
+ {
|
|
|
|
|
+ mems: []Member{
|
|
|
|
|
+ {ID: 1, ClientURLs: []string{"192.0.2.1"}},
|
|
|
|
|
+ },
|
|
|
|
|
+ wurls: []string{"http://192.0.2.1"},
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // single peer with a single address with a port
|
|
|
|
|
+ {
|
|
|
|
|
+ mems: []Member{
|
|
|
|
|
+ {ID: 1, ClientURLs: []string{"192.0.2.1:8001"}},
|
|
|
|
|
+ },
|
|
|
|
|
+ wurls: []string{"http://192.0.2.1:8001"},
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // several members explicitly unsorted
|
|
|
|
|
+ {
|
|
|
|
|
+ mems: []Member{
|
|
|
|
|
+ {ID: 2, ClientURLs: []string{"192.0.2.3", "192.0.2.4"}},
|
|
|
|
|
+ {ID: 3, ClientURLs: []string{"192.0.2.5", "192.0.2.6"}},
|
|
|
|
|
+ {ID: 1, ClientURLs: []string{"192.0.2.1", "192.0.2.2"}},
|
|
|
|
|
+ },
|
|
|
|
|
+ wurls: []string{"http://192.0.2.1", "http://192.0.2.2", "http://192.0.2.3", "http://192.0.2.4", "http://192.0.2.5", "http://192.0.2.6"},
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // no members
|
|
|
|
|
+ {
|
|
|
|
|
+ mems: []Member{},
|
|
|
|
|
+ wurls: []string{},
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // peer with no endpoints
|
|
|
|
|
+ {
|
|
|
|
|
+ mems: []Member{
|
|
|
|
|
+ {ID: 3, ClientURLs: []string{}},
|
|
|
|
|
+ },
|
|
|
|
|
+ wurls: []string{},
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for i, tt := range tests {
|
|
|
|
|
+ c := Cluster{}
|
|
|
|
|
+ if err := c.AddSlice(tt.mems); err != nil {
|
|
|
|
|
+ t.Errorf("AddSlice error: %v", err)
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ urls := c.ClientURLs()
|
|
|
|
|
+ if !reflect.DeepEqual(urls, tt.wurls) {
|
|
|
|
|
+ t.Errorf("#%d: ClientURLs = %v, want %v", i, tt.wurls, urls)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|