You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
759 B

  1. package metastore
  2. import (
  3. "testing"
  4. )
  5. func TestMemoryBacking(t *testing.T) {
  6. ms := &MetaStore{NewMetaStoreMemoryBacking()}
  7. verifySetGet(t, ms)
  8. }
  9. func TestFileBacking(t *testing.T) {
  10. ms := &MetaStore{NewMetaStoreFileBacking()}
  11. verifySetGet(t, ms)
  12. }
  13. func TestEtcdBacking(t *testing.T) {
  14. ms := &MetaStore{NewMetaStoreEtcdBacking("http://localhost:4001")}
  15. verifySetGet(t, ms)
  16. }
  17. func verifySetGet(t *testing.T, ms *MetaStore) {
  18. data := uint64(234234)
  19. ms.SetUint64("/tmp/sequence", data)
  20. if !ms.Has("/tmp/sequence") {
  21. t.Errorf("Failed to set data")
  22. }
  23. if val, err := ms.GetUint64("/tmp/sequence"); err == nil {
  24. if val != data {
  25. t.Errorf("Set %d, but read back %d", data, val)
  26. }
  27. } else {
  28. t.Errorf("Failed to get back data:%s", err)
  29. }
  30. }