github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/chunkDataPacks_test.go (about) 1 package operation 2 3 import ( 4 "testing" 5 6 "github.com/dgraph-io/badger/v3" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 storagemodel "github.com/koko1123/flow-go-1/storage/badger/model" 11 "github.com/koko1123/flow-go-1/utils/unittest" 12 ) 13 14 func TestChunkDataPack(t *testing.T) { 15 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 16 collectionID := unittest.IdentifierFixture() 17 expected := &storagemodel.StoredChunkDataPack{ 18 ChunkID: unittest.IdentifierFixture(), 19 StartState: unittest.StateCommitmentFixture(), 20 Proof: []byte{'p'}, 21 CollectionID: collectionID, 22 } 23 24 t.Run("Retrieve non-existent", func(t *testing.T) { 25 var actual storagemodel.StoredChunkDataPack 26 err := db.View(RetrieveChunkDataPack(expected.ChunkID, &actual)) 27 assert.Error(t, err) 28 }) 29 30 t.Run("Save", func(t *testing.T) { 31 err := db.Update(InsertChunkDataPack(expected)) 32 require.NoError(t, err) 33 34 var actual storagemodel.StoredChunkDataPack 35 err = db.View(RetrieveChunkDataPack(expected.ChunkID, &actual)) 36 assert.NoError(t, err) 37 38 assert.Equal(t, *expected, actual) 39 }) 40 41 t.Run("Remove", func(t *testing.T) { 42 err := db.Update(RemoveChunkDataPack(expected.ChunkID)) 43 require.NoError(t, err) 44 45 var actual storagemodel.StoredChunkDataPack 46 err = db.View(RetrieveChunkDataPack(expected.ChunkID, &actual)) 47 assert.Error(t, err) 48 }) 49 }) 50 }