From 11ce918401303f1004ad147edad335cacb724b25 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/syncmap/syncmap_test.go b/pkg/syncmap/syncmap_test.go index d3b57f153..65511acbc 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,16 @@ 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) + c.Check(result, check.IsNil) +}