convert the consul backend to use consul/testutil

Start up our own consul server for unit tests.
This commit is contained in:
James Bardin 2017-03-13 18:25:58 -04:00
parent 54224eb41e
commit 90055c6ae2
2 changed files with 12 additions and 21 deletions

View File

@ -2,10 +2,10 @@ package consul
import (
"fmt"
"os"
"testing"
"time"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/terraform/backend"
)
@ -14,15 +14,12 @@ func TestBackend_impl(t *testing.T) {
}
func TestBackend(t *testing.T) {
addr := os.Getenv("CONSUL_HTTP_ADDR")
if addr == "" {
t.Log("consul tests require CONSUL_HTTP_ADDR")
t.Skip()
}
srv := testutil.NewTestServer(t)
defer srv.Stop()
// Get the backend
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
"address": addr,
"address": srv.HTTPAddr,
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
})

View File

@ -2,10 +2,10 @@ package consul
import (
"fmt"
"os"
"testing"
"time"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/state/remote"
)
@ -16,15 +16,12 @@ func TestRemoteClient_impl(t *testing.T) {
}
func TestRemoteClient(t *testing.T) {
addr := os.Getenv("CONSUL_HTTP_ADDR")
if addr == "" {
t.Log("consul tests require CONSUL_HTTP_ADDR")
t.Skip()
}
srv := testutil.NewTestServer(t)
defer srv.Stop()
// Get the backend
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
"address": addr,
"address": srv.HTTPAddr,
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
})
@ -39,17 +36,14 @@ func TestRemoteClient(t *testing.T) {
}
func TestConsul_stateLock(t *testing.T) {
addr := os.Getenv("CONSUL_HTTP_ADDR")
if addr == "" {
t.Log("consul lock tests require CONSUL_HTTP_ADDR")
t.Skip()
}
srv := testutil.NewTestServer(t)
defer srv.Stop()
path := fmt.Sprintf("tf-unit/%s", time.Now().String())
// create 2 instances to get 2 remote.Clients
sA, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
"address": addr,
"address": srv.HTTPAddr,
"path": path,
}).State(backend.DefaultStateName)
if err != nil {
@ -57,7 +51,7 @@ func TestConsul_stateLock(t *testing.T) {
}
sB, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
"address": addr,
"address": srv.HTTPAddr,
"path": path,
}).State(backend.DefaultStateName)
if err != nil {