|
|
@@ -211,7 +211,7 @@ func TestBadParseRequest(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
for i, tt := range tests {
|
|
|
- got, err := parseRequest(tt.in, 1234, clockwork.NewFakeClock())
|
|
|
+ got, err := parseKeyRequest(tt.in, 1234, clockwork.NewFakeClock())
|
|
|
if err == nil {
|
|
|
t.Errorf("#%d: unexpected nil error!", i)
|
|
|
continue
|
|
|
@@ -244,7 +244,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
etcdserverpb.Request{
|
|
|
ID: 1234,
|
|
|
Method: "GET",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -258,7 +258,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
Val: "some_value",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -272,7 +272,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
PrevIndex: 98765,
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -286,7 +286,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
Recursive: true,
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -300,7 +300,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
Sorted: true,
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -310,7 +310,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "GET",
|
|
|
Wait: true,
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -319,7 +319,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
etcdserverpb.Request{
|
|
|
ID: 1234,
|
|
|
Method: "GET",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
Expiration: 0,
|
|
|
},
|
|
|
},
|
|
|
@@ -329,7 +329,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
etcdserverpb.Request{
|
|
|
ID: 1234,
|
|
|
Method: "GET",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
Expiration: fc.Now().Add(5678 * time.Second).UnixNano(),
|
|
|
},
|
|
|
},
|
|
|
@@ -339,7 +339,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
etcdserverpb.Request{
|
|
|
ID: 1234,
|
|
|
Method: "GET",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
Expiration: fc.Now().UnixNano(),
|
|
|
},
|
|
|
},
|
|
|
@@ -350,7 +350,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "GET",
|
|
|
Dir: true,
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -360,7 +360,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "GET",
|
|
|
Dir: false,
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -374,7 +374,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
PrevExist: boolp(true),
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -388,7 +388,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
PrevExist: boolp(false),
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
// mix various fields
|
|
|
@@ -408,7 +408,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
PrevExist: boolp(true),
|
|
|
PrevValue: "previous value",
|
|
|
Val: "some value",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
// query parameters should be used if given
|
|
|
@@ -422,7 +422,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
PrevValue: "woof",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
// but form values should take precedence over query parameters
|
|
|
@@ -438,13 +438,13 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
ID: 1234,
|
|
|
Method: "PUT",
|
|
|
PrevValue: "miaow",
|
|
|
- Path: "/foo",
|
|
|
+ Path: path.Join(etcdserver.StoreKeysPrefix, "/foo"),
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
- got, err := parseRequest(tt.in, 1234, fc)
|
|
|
+ got, err := parseKeyRequest(tt.in, 1234, fc)
|
|
|
if err != nil {
|
|
|
t.Errorf("#%d: err = %v, want %v", i, err, nil)
|
|
|
}
|
|
|
@@ -526,7 +526,7 @@ func (drt dummyRaftTimer) Term() uint64 { return uint64(5) }
|
|
|
func TestWriteEvent(t *testing.T) {
|
|
|
// nil event should not panic
|
|
|
rw := httptest.NewRecorder()
|
|
|
- writeEvent(rw, nil, dummyRaftTimer{})
|
|
|
+ writeKeyEvent(rw, nil, dummyRaftTimer{})
|
|
|
h := rw.Header()
|
|
|
if len(h) > 0 {
|
|
|
t.Fatalf("unexpected non-empty headers: %#v", h)
|
|
|
@@ -569,7 +569,7 @@ func TestWriteEvent(t *testing.T) {
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
rw := httptest.NewRecorder()
|
|
|
- writeEvent(rw, tt.ev, dummyRaftTimer{})
|
|
|
+ writeKeyEvent(rw, tt.ev, dummyRaftTimer{})
|
|
|
if gct := rw.Header().Get("Content-Type"); gct != "application/json" {
|
|
|
t.Errorf("case %d: bad Content-Type: got %q, want application/json", i, gct)
|
|
|
}
|
|
|
@@ -1240,7 +1240,7 @@ func TestHandleWatch(t *testing.T) {
|
|
|
}
|
|
|
tt.doToChan(wa.echan)
|
|
|
|
|
|
- handleWatch(tt.getCtx(), rw, wa, false, dummyRaftTimer{})
|
|
|
+ handleKeyWatch(tt.getCtx(), rw, wa, false, dummyRaftTimer{})
|
|
|
|
|
|
wcode := http.StatusOK
|
|
|
wct := "application/json"
|
|
|
@@ -1295,7 +1295,7 @@ func TestHandleWatchStreaming(t *testing.T) {
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
done := make(chan struct{})
|
|
|
go func() {
|
|
|
- handleWatch(ctx, rw, wa, true, dummyRaftTimer{})
|
|
|
+ handleKeyWatch(ctx, rw, wa, true, dummyRaftTimer{})
|
|
|
close(done)
|
|
|
}()
|
|
|
|
|
|
@@ -1561,6 +1561,86 @@ func TestServeAdminMembersDelete(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestTrimEventPrefix(t *testing.T) {
|
|
|
+ pre := "/abc"
|
|
|
+ tests := []struct {
|
|
|
+ ev *store.Event
|
|
|
+ wev *store.Event
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ nil,
|
|
|
+ nil,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ &store.Event{},
|
|
|
+ &store.Event{},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ &store.Event{Node: &store.NodeExtern{Key: "/abc/def"}},
|
|
|
+ &store.Event{Node: &store.NodeExtern{Key: "/def"}},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ &store.Event{PrevNode: &store.NodeExtern{Key: "/abc/ghi"}},
|
|
|
+ &store.Event{PrevNode: &store.NodeExtern{Key: "/ghi"}},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ &store.Event{
|
|
|
+ Node: &store.NodeExtern{Key: "/abc/def"},
|
|
|
+ PrevNode: &store.NodeExtern{Key: "/abc/ghi"},
|
|
|
+ },
|
|
|
+ &store.Event{
|
|
|
+ Node: &store.NodeExtern{Key: "/def"},
|
|
|
+ PrevNode: &store.NodeExtern{Key: "/ghi"},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for i, tt := range tests {
|
|
|
+ ev := trimEventPrefix(tt.ev, pre)
|
|
|
+ if !reflect.DeepEqual(ev, tt.wev) {
|
|
|
+ t.Errorf("#%d: event = %+v, want %+v", i, ev, tt.wev)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestTrimNodeExternPrefix(t *testing.T) {
|
|
|
+ pre := "/abc"
|
|
|
+ tests := []struct {
|
|
|
+ n *store.NodeExtern
|
|
|
+ wn *store.NodeExtern
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ nil,
|
|
|
+ nil,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ &store.NodeExtern{Key: "/abc/def"},
|
|
|
+ &store.NodeExtern{Key: "/def"},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ &store.NodeExtern{
|
|
|
+ Key: "/abc/def",
|
|
|
+ Nodes: []*store.NodeExtern{
|
|
|
+ {Key: "/abc/def/1"},
|
|
|
+ {Key: "/abc/def/2"},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ &store.NodeExtern{
|
|
|
+ Key: "/def",
|
|
|
+ Nodes: []*store.NodeExtern{
|
|
|
+ {Key: "/def/1"},
|
|
|
+ {Key: "/def/2"},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for i, tt := range tests {
|
|
|
+ n := trimNodeExternPrefix(tt.n, pre)
|
|
|
+ if !reflect.DeepEqual(n, tt.wn) {
|
|
|
+ t.Errorf("#%d: node = %+v, want %+v", i, n, tt.wn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type fakeCluster struct {
|
|
|
members []etcdserver.Member
|
|
|
}
|