cheapcash/append_test.go

49 lines
904 B
Go
Raw Normal View History

2021-11-16 04:56:33 +00:00
package cheapcash_test
import (
2021-11-16 05:13:49 +00:00
"errors"
2021-11-16 04:56:33 +00:00
"math/rand"
"strconv"
"testing"
"github.com/aldy505/cheapcash"
)
func TestAppend(t *testing.T) {
rand := strconv.Itoa(rand.Int())
c := cheapcash.Default()
err := c.Write(rand, []byte("Hello"))
if err != nil {
t.Error("an error was thrown:", err)
}
err = c.Append(rand, []byte("World"))
if err != nil {
t.Error("an error was thrown:", err)
}
r, err := c.Read(rand)
if err != nil {
t.Error("an error was thrown:", err)
}
if string(r) != "HelloWorld" {
t.Errorf("expected %s, got %v", "HelloWorld", string(r))
}
}
2021-11-16 05:13:49 +00:00
func TestAppend_NotExists(t *testing.T) {
rand := strconv.Itoa(rand.Int())
c := cheapcash.Default()
err := c.Append(rand, []byte("Hello"))
if err == nil {
t.Error("expected an error, got nil")
}
if !errors.Is(err, cheapcash.ErrNotExists) {
t.Errorf("expected %v, got %v", cheapcash.ErrNotExists, err)
}
}