|
@@ -16,6 +16,7 @@ import (
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
|
"github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
|
|
|
|
+ "github.com/coreos/etcd/Godeps/_workspace/src/github.com/jonboulle/clockwork"
|
|
|
etcdErr "github.com/coreos/etcd/error"
|
|
etcdErr "github.com/coreos/etcd/error"
|
|
|
"github.com/coreos/etcd/etcdserver"
|
|
"github.com/coreos/etcd/etcdserver"
|
|
|
"github.com/coreos/etcd/etcdserver/etcdserverpb"
|
|
"github.com/coreos/etcd/etcdserver/etcdserverpb"
|
|
@@ -194,7 +195,7 @@ func TestBadParseRequest(t *testing.T) {
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
- got, err := parseRequest(tt.in, 1234)
|
|
|
|
|
|
|
+ got, err := parseRequest(tt.in, 1234, clockwork.NewFakeClock())
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
t.Errorf("#%d: unexpected nil error!", i)
|
|
t.Errorf("#%d: unexpected nil error!", i)
|
|
|
continue
|
|
continue
|
|
@@ -215,6 +216,8 @@ func TestBadParseRequest(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func TestGoodParseRequest(t *testing.T) {
|
|
func TestGoodParseRequest(t *testing.T) {
|
|
|
|
|
+ fc := clockwork.NewFakeClock()
|
|
|
|
|
+ fc.Tick(1111)
|
|
|
tests := []struct {
|
|
tests := []struct {
|
|
|
in *http.Request
|
|
in *http.Request
|
|
|
w etcdserverpb.Request
|
|
w etcdserverpb.Request
|
|
@@ -304,6 +307,26 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
Expiration: 0,
|
|
Expiration: 0,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ // non-empty TTL specified
|
|
|
|
|
+ mustNewRequest(t, "foo?ttl=5678"),
|
|
|
|
|
+ etcdserverpb.Request{
|
|
|
|
|
+ ID: 1234,
|
|
|
|
|
+ Method: "GET",
|
|
|
|
|
+ Path: "/foo",
|
|
|
|
|
+ Expiration: fc.Now().Add(5678 * time.Second).UnixNano(),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ // zero TTL specified
|
|
|
|
|
+ mustNewRequest(t, "foo?ttl=0"),
|
|
|
|
|
+ etcdserverpb.Request{
|
|
|
|
|
+ ID: 1234,
|
|
|
|
|
+ Method: "GET",
|
|
|
|
|
+ Path: "/foo",
|
|
|
|
|
+ Expiration: fc.Now().UnixNano(),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
// dir specified
|
|
// dir specified
|
|
|
mustNewRequest(t, "foo?dir=true"),
|
|
mustNewRequest(t, "foo?dir=true"),
|
|
@@ -405,7 +428,7 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
- got, err := parseRequest(tt.in, 1234)
|
|
|
|
|
|
|
+ got, err := parseRequest(tt.in, 1234, fc)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Errorf("#%d: err = %v, want %v", i, err, nil)
|
|
t.Errorf("#%d: err = %v, want %v", i, err, nil)
|
|
|
}
|
|
}
|
|
@@ -413,27 +436,6 @@ func TestGoodParseRequest(t *testing.T) {
|
|
|
t.Errorf("#%d: request=%#v, want %#v", i, got, tt.w)
|
|
t.Errorf("#%d: request=%#v, want %#v", i, got, tt.w)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Test TTL separately until we don't rely on the time module...
|
|
|
|
|
- now := time.Now().UnixNano()
|
|
|
|
|
- req := mustNewForm(t, "foo", url.Values{"ttl": []string{"100"}})
|
|
|
|
|
- got, err := parseRequest(req, 1234)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- t.Fatalf("err = %v, want nil", err)
|
|
|
|
|
- }
|
|
|
|
|
- if got.Expiration <= now {
|
|
|
|
|
- t.Fatalf("expiration = %v, wanted > %v", got.Expiration, now)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // ensure TTL=0 results in an expiration time
|
|
|
|
|
- req = mustNewForm(t, "foo", url.Values{"ttl": []string{"0"}})
|
|
|
|
|
- got, err = parseRequest(req, 1234)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- t.Fatalf("err = %v, want nil", err)
|
|
|
|
|
- }
|
|
|
|
|
- if got.Expiration <= now {
|
|
|
|
|
- t.Fatalf("expiration = %v, wanted > %v", got.Expiration, now)
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// eventingWatcher immediately returns a simple event of the given action on its channel
|
|
// eventingWatcher immediately returns a simple event of the given action on its channel
|