mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-10 07:35:34 -06:00
convert the consul backend to use consul/testutil
Start up our own consul server for unit tests.
This commit is contained in:
parent
54224eb41e
commit
90055c6ae2
@ -2,10 +2,10 @@ package consul
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/testutil"
|
||||||
"github.com/hashicorp/terraform/backend"
|
"github.com/hashicorp/terraform/backend"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,15 +14,12 @@ func TestBackend_impl(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBackend(t *testing.T) {
|
func TestBackend(t *testing.T) {
|
||||||
addr := os.Getenv("CONSUL_HTTP_ADDR")
|
srv := testutil.NewTestServer(t)
|
||||||
if addr == "" {
|
defer srv.Stop()
|
||||||
t.Log("consul tests require CONSUL_HTTP_ADDR")
|
|
||||||
t.Skip()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the backend
|
// Get the backend
|
||||||
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||||
"address": addr,
|
"address": srv.HTTPAddr,
|
||||||
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
|
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@ package consul
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/testutil"
|
||||||
"github.com/hashicorp/terraform/backend"
|
"github.com/hashicorp/terraform/backend"
|
||||||
"github.com/hashicorp/terraform/state/remote"
|
"github.com/hashicorp/terraform/state/remote"
|
||||||
)
|
)
|
||||||
@ -16,15 +16,12 @@ func TestRemoteClient_impl(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoteClient(t *testing.T) {
|
func TestRemoteClient(t *testing.T) {
|
||||||
addr := os.Getenv("CONSUL_HTTP_ADDR")
|
srv := testutil.NewTestServer(t)
|
||||||
if addr == "" {
|
defer srv.Stop()
|
||||||
t.Log("consul tests require CONSUL_HTTP_ADDR")
|
|
||||||
t.Skip()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the backend
|
// Get the backend
|
||||||
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||||
"address": addr,
|
"address": srv.HTTPAddr,
|
||||||
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
|
"path": fmt.Sprintf("tf-unit/%s", time.Now().String()),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -39,17 +36,14 @@ func TestRemoteClient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConsul_stateLock(t *testing.T) {
|
func TestConsul_stateLock(t *testing.T) {
|
||||||
addr := os.Getenv("CONSUL_HTTP_ADDR")
|
srv := testutil.NewTestServer(t)
|
||||||
if addr == "" {
|
defer srv.Stop()
|
||||||
t.Log("consul lock tests require CONSUL_HTTP_ADDR")
|
|
||||||
t.Skip()
|
|
||||||
}
|
|
||||||
|
|
||||||
path := fmt.Sprintf("tf-unit/%s", time.Now().String())
|
path := fmt.Sprintf("tf-unit/%s", time.Now().String())
|
||||||
|
|
||||||
// create 2 instances to get 2 remote.Clients
|
// create 2 instances to get 2 remote.Clients
|
||||||
sA, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
sA, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||||
"address": addr,
|
"address": srv.HTTPAddr,
|
||||||
"path": path,
|
"path": path,
|
||||||
}).State(backend.DefaultStateName)
|
}).State(backend.DefaultStateName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -57,7 +51,7 @@ func TestConsul_stateLock(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sB, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
sB, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||||
"address": addr,
|
"address": srv.HTTPAddr,
|
||||||
"path": path,
|
"path": path,
|
||||||
}).State(backend.DefaultStateName)
|
}).State(backend.DefaultStateName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user