You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
499 B

  1. package db
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestMemDbIterator(t *testing.T) {
  7. db := NewMemDB()
  8. keys := make([][]byte, 100)
  9. for i := 0; i < 100; i++ {
  10. keys[i] = []byte{byte(i)}
  11. }
  12. value := []byte{5}
  13. for _, k := range keys {
  14. db.Set(k, value)
  15. }
  16. iter := db.Iterator()
  17. i := 0
  18. for iter.Next() {
  19. assert.Equal(t, db.Get(iter.Key()), iter.Value(), "values dont match for key")
  20. i += 1
  21. }
  22. assert.Equal(t, i, len(db.db), "iterator didnt cover whole db")
  23. }