Skip to content

Commit

Permalink
add test coverage for set
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshi-099 committed Oct 20, 2023
1 parent 9190941 commit 0df74f6
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions rotom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,61 @@ func TestHMap(t *testing.T) {
assert.Equal(err, base.ErrWrongType)
}
}

func TestSet(t *testing.T) {
assert := assert.New(t)

db, err := Open(NoPersistentConfig)
if err != nil {
panic(err)
}

for i := 0; i < 10000; i++ {
// gen random data
key := gofakeit.UUID()
field := gofakeit.UUID()
op := gofakeit.Number(0, 100)

// test
err := db.SAdd(key, field)
assert.Nil(err)

ok, err := db.SHas(key, field)
assert.True(ok)
assert.Nil(err)

if op%3 == 0 {
err = db.SRemove(key, field)
assert.Nil(err)

ok, err := db.SHas(key, field)
assert.False(ok)
assert.Nil(err)
}
}

// err test
db.Set("str", []byte(""))
{
// add
err := db.SAdd("str", "foo")
assert.Equal(err, base.ErrWrongType)
}
{
// card
res, err := db.SCard("str")
assert.Equal(res, 0)
assert.Equal(err, base.ErrWrongType)
}
{
// has
ok, err := db.SHas("str", "foo")
assert.False(ok)
assert.Equal(err, base.ErrWrongType)
}
{
// remove
err := db.SRemove("str", "foo")
assert.Equal(err, base.ErrWrongType)
}
}

0 comments on commit 0df74f6

Please sign in to comment.