From e1990cdce0fa817f17cb9831f7be31afe5d88a8e Mon Sep 17 00:00:00 2001 From: Burak Sezer Date: Wed, 9 Dec 2020 21:49:13 +0300 Subject: [PATCH] fix: wrong type of extra in Put method and check it correctly --- client/dmap.go | 2 +- client/dmap_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/client/dmap.go b/client/dmap.go index e2379ae0..c41b1bfb 100644 --- a/client/dmap.go +++ b/client/dmap.go @@ -88,7 +88,7 @@ func (d *DMap) Put(key string, value interface{}) error { req.SetDMap(d.name) req.SetKey(key) req.SetValue(data) - req.SetExtra(protocol.PutExExtra{ + req.SetExtra(protocol.PutExtra{ Timestamp: time.Now().UnixNano(), }) resp, err := d.request(req) diff --git a/client/dmap_test.go b/client/dmap_test.go index ef0076c6..b6b4b1e2 100644 --- a/client/dmap_test.go +++ b/client/dmap_test.go @@ -141,6 +141,22 @@ func TestClient_Put(t *testing.T) { if val.(string) != value { t.Fatalf("Expected value %s. Got: %s", val.(string), value) } + + t.Run("check olric.Entry fields", func(t *testing.T) { + entry, err := dm.GetEntry(key) + if err != nil { + t.Fatalf("Expected nil. Got: %v", err) + } + if entry.Value.(string) != value { + t.Fatalf("Expected value %s. Got: %s", entry.Value.(string), value) + } + if entry.Timestamp == 0 { + t.Fatalf("Timestamp is invalid") + } + if entry.TTL != 0 { + t.Fatalf("TTL is invalid") + } + }) } func TestClient_PutEx(t *testing.T) {