etcdserver: init time.Time only if Expiration > 0
golang's concept of "zero" time does not align with the zero value of a unix timestamp. Initializing time.Time with a unix timestamp of 0 makes time.Time.IsZero fail. Solve this by initializing time.Time only if we care about the time.
This commit is contained in:
@ -16,6 +16,33 @@ import (
|
||||
"github.com/coreos/etcd/third_party/code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
func TestGetExpirationTime(t *testing.T) {
|
||||
tests := []struct {
|
||||
r pb.Request
|
||||
want time.Time
|
||||
}{
|
||||
{
|
||||
pb.Request{Expiration: 0},
|
||||
time.Time{},
|
||||
},
|
||||
{
|
||||
pb.Request{Expiration: 60000},
|
||||
time.Unix(0, 60000),
|
||||
},
|
||||
{
|
||||
pb.Request{Expiration: -60000},
|
||||
time.Unix(0, -60000),
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
got := getExpirationTime(&tt.r)
|
||||
if !reflect.DeepEqual(tt.want, got) {
|
||||
t.Errorf("#%d: incorrect expiration time: want=%v got=%v", i, tt.want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoLocalAction tests requests which do not need to go through raft to be applied,
|
||||
// and are served through local data.
|
||||
func TestDoLocalAction(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user