mirror of https://github.com/aldy505/cheapcash.git
test: add more test cases
This commit is contained in:
parent
07a1b112fe
commit
e6f33ca1d4
|
@ -1,6 +1,7 @@
|
|||
package cheapcash_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
@ -31,3 +32,17 @@ func TestAppend(t *testing.T) {
|
|||
t.Errorf("expected %s, got %v", "HelloWorld", string(r))
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cheapcash_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
@ -57,3 +58,17 @@ func TestRead_Concurrency(t *testing.T) {
|
|||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestRead_NotExists(t *testing.T) {
|
||||
rand := strconv.Itoa(rand.Int())
|
||||
c := cheapcash.Default()
|
||||
|
||||
_, err := c.Read(rand)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package cheapcash_test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
|
@ -37,3 +39,18 @@ func TestWrite_Concurrency(t *testing.T) {
|
|||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestWrite_Exists(t *testing.T) {
|
||||
rand := strconv.Itoa(rand.Int())
|
||||
c := cheapcash.Default()
|
||||
|
||||
err := c.Write(rand, []byte("value"))
|
||||
if err != nil {
|
||||
t.Error("an error was thrown:", err)
|
||||
}
|
||||
|
||||
err = c.Write(rand, []byte("another value"))
|
||||
if err != nil {
|
||||
t.Error("an error was thrown:", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue