2016-03-03 09:39:19 +01:00
|
|
|
// Copyright 2016 The Chihaya Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by the BSD 2-Clause license,
|
|
|
|
// which can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2016-05-01 23:56:07 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/chihaya/chihaya/server/store"
|
2016-03-03 09:39:19 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
driver = &stringStoreDriver{}
|
|
|
|
s1 = "abc"
|
|
|
|
s2 = "def"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStringStore(t *testing.T) {
|
2016-03-11 21:09:49 +01:00
|
|
|
ss, err := driver.New(&store.DriverConfig{})
|
2016-03-03 09:39:19 +01:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
has, err := ss.HasString(s1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.False(t, has)
|
|
|
|
|
|
|
|
has, err = ss.HasString(s2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.False(t, has)
|
|
|
|
|
|
|
|
err = ss.RemoveString(s1)
|
2016-05-01 23:56:07 +02:00
|
|
|
assert.NotNil(t, err)
|
2016-03-03 09:39:19 +01:00
|
|
|
|
|
|
|
err = ss.PutString(s1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
has, err = ss.HasString(s1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.True(t, has)
|
|
|
|
|
|
|
|
has, err = ss.HasString(s2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.False(t, has)
|
|
|
|
|
|
|
|
err = ss.PutString(s1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = ss.PutString(s2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
has, err = ss.HasString(s1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.True(t, has)
|
|
|
|
|
|
|
|
has, err = ss.HasString(s2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.True(t, has)
|
|
|
|
|
|
|
|
err = ss.RemoveString(s1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = ss.RemoveString(s2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
has, err = ss.HasString(s1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.False(t, has)
|
|
|
|
|
|
|
|
has, err = ss.HasString(s2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.False(t, has)
|
|
|
|
}
|