Refactor etcd test instance into wrapper
@@ -3,16 +3,15 @@ package etcd
import (
"fmt"
"log"
- "os"
- "runtime/pprof"
"testing"
+ "github.com/sensu/sensu-go/backend/store"
"github.com/sensu/sensu-go/testing/util"
"github.com/sensu/sensu-go/types"
"github.com/stretchr/testify/assert"
)
-func TestEtcdStore(t *testing.T) {
+func testWithEtcd(t *testing.T, f func(store.Store)) {
util.WithTempDir(func(tmpDir string) {
ports := make([]int, 2)
err := util.RandomPorts(ports)
@@ -22,7 +21,6 @@ func TestEtcdStore(t *testing.T) {
clURL := fmt.Sprintf("http://127.0.0.1:%d", ports[0])
apURL := fmt.Sprintf("http://127.0.0.1:%d", ports[1])
initCluster := fmt.Sprintf("default=%s", apURL)
- fmt.Println(initCluster)
cfg := NewConfig()
cfg.StateDir = tmpDir
@@ -31,27 +29,27 @@ func TestEtcdStore(t *testing.T) {
cfg.InitialCluster = initCluster
e, err := NewEtcd(cfg)
+ assert.NoError(t, err)
if e != nil {
defer e.Shutdown()
}
- assert.NoError(t, err)
- if err != nil {
- pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
- pprof.Lookup("threadcreate").WriteTo(os.Stdout, 1)
- pprof.Lookup("heap").WriteTo(os.Stdout, 1)
- assert.FailNow(t, "unable to start new etcd")
- }
- store, err := e.NewStore()
+ s, err := e.NewStore()
assert.NoError(t, err)
if err != nil {
assert.FailNow(t, "failed to get store from etcd")
}
+ f(s)
+ })
+}
+
+func TestEntityStorage(t *testing.T) {
+ testWithEtcd(t, func(store store.Store) {
entity := &types.Entity{
ID: "0",
}
- err = store.UpdateEntity(entity)
+ err := store.UpdateEntity(entity)
assert.NoError(t, err)
retrieved, err := store.GetEntityByID(entity.ID)
assert.NoError(t, err)
