2017-01-19 05:49:01 +01:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-02-07 16:05:53 +01:00
|
|
|
"os"
|
2017-01-19 05:49:01 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/backend"
|
|
|
|
"github.com/hashicorp/terraform/state/remote"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoteClient_impl(t *testing.T) {
|
|
|
|
var _ remote.Client = new(RemoteClient)
|
2017-02-15 23:20:59 +01:00
|
|
|
var _ remote.ClientLocker = new(RemoteClient)
|
2017-01-19 05:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteClient(t *testing.T) {
|
2017-02-08 16:51:51 +01:00
|
|
|
addr := os.Getenv("CONSUL_HTTP_ADDR")
|
|
|
|
if addr == "" {
|
|
|
|
t.Log("consul tests require CONSUL_HTTP_ADDR")
|
|
|
|
t.Skip()
|
|
|
|
}
|
2017-01-19 05:49:01 +01:00
|
|
|
|
|
|
|
// Get the backend
|
|
|
|
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
2017-02-08 16:51:51 +01:00
|
|
|
"address": addr,
|
2017-01-19 05:49:01 +01:00
|
|
|
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
|
|
|
|
})
|
|
|
|
|
2017-03-02 07:15:08 +01:00
|
|
|
// Grab the client
|
|
|
|
state, err := b.State(backend.DefaultStateName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2017-01-19 05:49:01 +01:00
|
|
|
// Test
|
2017-03-02 07:15:08 +01:00
|
|
|
remote.TestClient(t, state.(*remote.State).Client)
|
2017-01-19 05:49:01 +01:00
|
|
|
}
|
2017-02-07 16:05:53 +01:00
|
|
|
|
|
|
|
func TestConsul_stateLock(t *testing.T) {
|
|
|
|
addr := os.Getenv("CONSUL_HTTP_ADDR")
|
|
|
|
if addr == "" {
|
2017-02-07 16:33:05 +01:00
|
|
|
t.Log("consul lock tests require CONSUL_HTTP_ADDR")
|
2017-02-07 16:05:53 +01:00
|
|
|
t.Skip()
|
|
|
|
}
|
|
|
|
|
2017-02-07 16:33:05 +01:00
|
|
|
path := fmt.Sprintf("tf-unit/%s", time.Now().String())
|
2017-02-07 16:05:53 +01:00
|
|
|
|
|
|
|
// create 2 instances to get 2 remote.Clients
|
2017-02-07 16:33:05 +01:00
|
|
|
sA, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
2017-02-07 16:05:53 +01:00
|
|
|
"address": addr,
|
|
|
|
"path": path,
|
2017-02-27 23:09:26 +01:00
|
|
|
}).State(backend.DefaultStateName)
|
2017-02-07 16:33:05 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sB, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
2017-02-07 16:05:53 +01:00
|
|
|
"address": addr,
|
|
|
|
"path": path,
|
2017-02-27 23:09:26 +01:00
|
|
|
}).State(backend.DefaultStateName)
|
2017-02-07 16:33:05 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-02-07 16:05:53 +01:00
|
|
|
|
2017-02-07 16:33:05 +01:00
|
|
|
remote.TestRemoteLocks(t, sA.(*remote.State).Client, sB.(*remote.State).Client)
|
2017-02-07 16:05:53 +01:00
|
|
|
}
|