2018-02-07 21:21:20 +01:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
2019-11-14 01:11:35 +01:00
|
|
|
"github.com/lbryio/lbry.go/v2/extras/errors"
|
2018-02-07 21:21:20 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMemoryBlobStore_Put(t *testing.T) {
|
2020-10-22 19:12:31 +02:00
|
|
|
s := NewMemoryStore()
|
2018-02-07 21:21:20 +01:00
|
|
|
blob := []byte("abcdefg")
|
|
|
|
err := s.Put("abc", blob)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMemoryBlobStore_Get(t *testing.T) {
|
2020-10-22 19:12:31 +02:00
|
|
|
s := NewMemoryStore()
|
2018-02-07 21:21:20 +01:00
|
|
|
hash := "abc"
|
|
|
|
blob := []byte("abcdefg")
|
2018-06-15 04:30:37 +02:00
|
|
|
err := s.Put(hash, blob)
|
|
|
|
if err != nil {
|
2018-05-30 03:38:55 +02:00
|
|
|
t.Error("error getting memory blob - ", err)
|
|
|
|
}
|
2018-02-07 21:21:20 +01:00
|
|
|
|
|
|
|
gotBlob, err := s.Get(hash)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(gotBlob, blob) {
|
|
|
|
t.Error("Got blob that is different from expected blob")
|
|
|
|
}
|
|
|
|
|
|
|
|
missingBlob, err := s.Get("nonexistent hash")
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Expected ErrBlobNotFound, got nil")
|
|
|
|
}
|
|
|
|
if !errors.Is(err, ErrBlobNotFound) {
|
|
|
|
t.Errorf("Received unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(missingBlob, []byte{}) {
|
|
|
|
t.Error("Got blob that is not empty")
|
|
|
|
}
|
|
|
|
}
|