2013-11-05 09:59:00 +00:00
|
|
|
package metastore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMemoryBacking(t *testing.T) {
|
|
|
|
ms := &MetaStore{NewMetaStoreMemoryBacking()}
|
|
|
|
verifySetGet(t, ms)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFileBacking(t *testing.T) {
|
|
|
|
ms := &MetaStore{NewMetaStoreFileBacking()}
|
|
|
|
verifySetGet(t, ms)
|
|
|
|
}
|
|
|
|
|
2013-11-10 09:31:50 +00:00
|
|
|
func TestEtcdBacking(t *testing.T) {
|
|
|
|
ms := &MetaStore{NewMetaStoreEtcdBacking("http://localhost:4001")}
|
|
|
|
verifySetGet(t, ms)
|
|
|
|
}
|
|
|
|
|
2013-11-05 09:59:00 +00:00
|
|
|
func verifySetGet(t *testing.T, ms *MetaStore) {
|
|
|
|
data := uint64(234234)
|
2013-11-10 09:31:50 +00:00
|
|
|
ms.SetUint64("/tmp/sequence", data)
|
|
|
|
if !ms.Has("/tmp/sequence") {
|
2013-11-05 09:59:00 +00:00
|
|
|
t.Errorf("Failed to set data")
|
|
|
|
}
|
2013-11-10 09:31:50 +00:00
|
|
|
if val, err := ms.GetUint64("/tmp/sequence"); err == nil {
|
2013-11-05 09:59:00 +00:00
|
|
|
if val != data {
|
|
|
|
t.Errorf("Set %d, but read back %d", data, val)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t.Errorf("Failed to get back data:%s", err)
|
|
|
|
}
|
|
|
|
}
|