etcd: Rewrite embed etcd implementation

This is a giant cleanup of the etcd code. The earlier version was
written when I was less experienced with golang.

This is still not perfect, and does contain some races, but at least
it's a decent base to start from. The automatic elastic clustering
should be considered an experimental feature. If you need a more
battle-tested cluster, then you should manage etcd manually and point
mgmt at your existing cluster.
This commit is contained in:
James Shubin
2018-05-05 17:35:08 -04:00
parent fb275d9537
commit a5842a41b2
56 changed files with 5459 additions and 2654 deletions

View File

@@ -22,6 +22,7 @@ package util
import (
"reflect"
"sort"
"strings"
"testing"
)
@@ -1014,6 +1015,76 @@ func TestRemovePathPrefix0(t *testing.T) {
}
}
func TestPriorityStrSliceSort0(t *testing.T) {
in := []string{"foo", "bar", "baz"}
ex := []string{"bar", "baz", "foo"}
fn := func(x string) bool {
return x == "foo"
}
out := PriorityStrSliceSort(in, fn)
if !reflect.DeepEqual(ex, out) {
t.Errorf("PriorityStrSliceSort expected: %v; got: %v.", ex, out)
}
}
func TestPriorityStrSliceSort1(t *testing.T) {
in := []string{"foo", "bar", "baz"}
ex := []string{"bar", "foo", "baz"}
fn := func(x string) bool {
return x != "bar" // != brings this key to the front
}
out := PriorityStrSliceSort(in, fn)
if !reflect.DeepEqual(ex, out) {
t.Errorf("PriorityStrSliceSort expected: %v; got: %v.", ex, out)
}
}
func TestPriorityStrSliceSort2(t *testing.T) {
in := []string{"bar", "foo", "bar", "bar", "baz"}
ex := []string{"foo", "baz", "bar", "bar", "bar"}
fn := func(x string) bool {
return x == "bar"
}
out := PriorityStrSliceSort(in, fn)
if !reflect.DeepEqual(ex, out) {
t.Errorf("PriorityStrSliceSort expected: %v; got: %v.", ex, out)
}
}
func TestPriorityStrSliceSort3(t *testing.T) {
in := []string{"foo", "bar1", "bar2", "bar3", "baz"}
ex := []string{"bar1", "bar2", "bar3", "foo", "baz"}
fn := func(x string) bool {
return !strings.HasPrefix(x, "bar")
}
out := PriorityStrSliceSort(in, fn)
if !reflect.DeepEqual(ex, out) {
t.Errorf("PriorityStrSliceSort expected: %v; got: %v.", ex, out)
}
}
func TestPriorityStrSliceSort4(t *testing.T) {
in := []string{"foo", "bar1", "bar2", "bar3", "baz"}
ex := []string{"foo", "baz", "bar1", "bar2", "bar3"}
fn := func(x string) bool {
return strings.HasPrefix(x, "bar")
}
out := PriorityStrSliceSort(in, fn)
if !reflect.DeepEqual(ex, out) {
t.Errorf("PriorityStrSliceSort expected: %v; got: %v.", ex, out)
}
}
func TestSortedStrSliceCompare0(t *testing.T) {
slice0 := []string{"foo", "bar", "baz"}
slice1 := []string{"bar", "foo", "baz"}