github.com/koko1123/flow-go-1@v0.29.6/module/mempool/stdmap/guarantees_test.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package stdmap_test 4 5 import ( 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 11 "github.com/koko1123/flow-go-1/model/flow" 12 "github.com/koko1123/flow-go-1/module/mempool/stdmap" 13 ) 14 15 func TestGuaranteePool(t *testing.T) { 16 item1 := &flow.CollectionGuarantee{ 17 CollectionID: flow.Identifier{0x01}, 18 } 19 item2 := &flow.CollectionGuarantee{ 20 CollectionID: flow.Identifier{0x02}, 21 } 22 23 pool, err := stdmap.NewGuarantees(1000) 24 require.NoError(t, err) 25 26 t.Run("should be able to add first", func(t *testing.T) { 27 added := pool.Add(item1) 28 assert.True(t, added) 29 }) 30 31 t.Run("should be able to add second", func(t *testing.T) { 32 added := pool.Add(item2) 33 assert.True(t, added) 34 }) 35 36 t.Run("should be able to get size", func(t *testing.T) { 37 size := pool.Size() 38 assert.EqualValues(t, 2, size) 39 }) 40 41 t.Run("should be able to get first", func(t *testing.T) { 42 got, exists := pool.ByID(item1.ID()) 43 assert.True(t, exists) 44 assert.Equal(t, item1, got) 45 }) 46 47 t.Run("should be able to remove second", func(t *testing.T) { 48 ok := pool.Remove(item2.ID()) 49 assert.True(t, ok) 50 }) 51 52 t.Run("should be able to retrieve all", func(t *testing.T) { 53 items := pool.All() 54 assert.Len(t, items, 1) 55 assert.Equal(t, item1, items[0]) 56 }) 57 }