2017-03-02 07:58:51 +01:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-03-14 15:49:38 +01:00
|
|
|
"io/ioutil"
|
2017-03-14 19:41:16 +01:00
|
|
|
"os"
|
2017-03-02 07:58:51 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-03-13 23:25:58 +01:00
|
|
|
"github.com/hashicorp/consul/testutil"
|
2017-03-02 07:58:51 +01:00
|
|
|
"github.com/hashicorp/terraform/backend"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBackend_impl(t *testing.T) {
|
|
|
|
var _ backend.Backend = new(Backend)
|
|
|
|
}
|
|
|
|
|
2017-03-14 15:49:38 +01:00
|
|
|
func newConsulTestServer(t *testing.T) *testutil.TestServer {
|
2017-03-14 19:41:16 +01:00
|
|
|
skip := os.Getenv("TF_ACC") == "" && os.Getenv("TF_CONSUL_TEST") == ""
|
|
|
|
if skip {
|
|
|
|
t.Log("consul server tests require setting TF_ACC or TF_CONSUL_TEST")
|
|
|
|
t.Skip()
|
|
|
|
}
|
|
|
|
|
2017-03-14 15:49:38 +01:00
|
|
|
srv := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
|
|
|
|
c.LogLevel = "warn"
|
|
|
|
|
|
|
|
if !testing.Verbose() {
|
|
|
|
c.Stdout = ioutil.Discard
|
|
|
|
c.Stderr = ioutil.Discard
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return srv
|
|
|
|
}
|
|
|
|
|
2017-03-02 07:58:51 +01:00
|
|
|
func TestBackend(t *testing.T) {
|
2017-03-14 15:49:38 +01:00
|
|
|
srv := newConsulTestServer(t)
|
2017-03-13 23:25:58 +01:00
|
|
|
defer srv.Stop()
|
2017-03-02 07:58:51 +01:00
|
|
|
|
2017-03-15 01:28:42 +01:00
|
|
|
path := fmt.Sprintf("tf-unit/%s", time.Now().String())
|
|
|
|
|
|
|
|
// Get the backend. We need two to test locking.
|
|
|
|
b1 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
2017-03-13 23:25:58 +01:00
|
|
|
"address": srv.HTTPAddr,
|
2017-03-15 01:28:42 +01:00
|
|
|
"path": path,
|
|
|
|
})
|
|
|
|
|
|
|
|
b2 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
|
|
|
"address": srv.HTTPAddr,
|
|
|
|
"path": path,
|
2017-03-02 07:58:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// Test
|
2017-03-15 01:28:42 +01:00
|
|
|
backend.TestBackend(t, b1, b2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackend_lockDisabled(t *testing.T) {
|
|
|
|
srv := newConsulTestServer(t)
|
|
|
|
defer srv.Stop()
|
|
|
|
|
|
|
|
path := fmt.Sprintf("tf-unit/%s", time.Now().String())
|
|
|
|
|
|
|
|
// Get the backend. We need two to test locking.
|
|
|
|
b1 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
|
|
|
"address": srv.HTTPAddr,
|
|
|
|
"path": path,
|
|
|
|
"lock": false,
|
|
|
|
})
|
|
|
|
|
|
|
|
b2 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
|
|
|
"address": srv.HTTPAddr,
|
|
|
|
"path": path + "different", // Diff so locking test would fail if it was locking
|
|
|
|
"lock": false,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Test
|
|
|
|
backend.TestBackend(t, b1, b2)
|
2017-03-02 07:58:51 +01:00
|
|
|
}
|
2017-03-14 20:24:50 +01:00
|
|
|
|
|
|
|
func TestBackend_gzip(t *testing.T) {
|
|
|
|
srv := newConsulTestServer(t)
|
|
|
|
defer srv.Stop()
|
|
|
|
|
|
|
|
// Get the backend
|
|
|
|
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
|
|
|
"address": srv.HTTPAddr,
|
|
|
|
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
|
|
|
|
"gzip": true,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Test
|
2017-03-15 01:59:54 +01:00
|
|
|
backend.TestBackend(t, b, nil)
|
2017-03-14 20:24:50 +01:00
|
|
|
}
|