From f148faffafc498d5c5b74b5155bde1ec8b840196 Mon Sep 17 00:00:00 2001 From: Zhou Hao Date: Wed, 12 Feb 2020 14:01:15 +0800 Subject: [PATCH] pkg/syncmap: add unit test for GetAsAtomicInt Signed-off-by: Zhou Hao --- pkg/syncmap/syncmap_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/syncmap/syncmap_test.go b/pkg/syncmap/syncmap_test.go index d3b57f153..acc9f2c5c 100644 --- a/pkg/syncmap/syncmap_test.go +++ b/pkg/syncmap/syncmap_test.go @@ -21,6 +21,8 @@ import ( "testing" "time" + "github.com/dragonflyoss/Dragonfly/pkg/atomiccount" + "github.com/go-check/check" "github.com/willf/bitset" ) @@ -131,3 +133,15 @@ func (suite *SyncMapUtilSuite) TestGetAsTime(c *check.C) { result, _ := mmap.GetAsTime("aaa") c.Check(result, check.DeepEquals, expected) } + +func (suite *SyncMapUtilSuite) TestGetAsAtomicInt(c *check.C) { + expected := atomiccount.NewAtomicInt(10) + mmap := NewSyncMap() + mmap.Add("aaa", expected) + + result, _ := mmap.GetAsAtomicInt("aaa") + c.Check(result, check.DeepEquals, expected) + + result, err := mmap.GetAsAtomicInt("nonexist") + c.Check(err, check.NotNil) +}