2018-03-17 00:30:07 +01:00
|
|
|
package etcdv2
|
2015-10-12 23:04:58 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2018-03-17 00:30:07 +01:00
|
|
|
|
2021-05-17 17:42:17 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/backend"
|
2021-05-17 21:17:09 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/configs"
|
2021-05-17 21:43:35 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/states/remote"
|
2018-03-21 02:43:02 +01:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
2015-10-12 23:04:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEtcdClient_impl(t *testing.T) {
|
2018-03-17 00:30:07 +01:00
|
|
|
var _ remote.Client = new(EtcdClient)
|
2015-10-12 23:04:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEtcdClient(t *testing.T) {
|
|
|
|
endpoint := os.Getenv("ETCD_ENDPOINT")
|
|
|
|
if endpoint == "" {
|
|
|
|
t.Skipf("skipping; ETCD_ENDPOINT must be set")
|
|
|
|
}
|
|
|
|
|
2018-03-17 00:30:07 +01:00
|
|
|
// Get the backend
|
2018-03-21 02:43:02 +01:00
|
|
|
config := map[string]cty.Value{
|
|
|
|
"endpoints": cty.StringVal(endpoint),
|
|
|
|
"path": cty.StringVal(fmt.Sprintf("tf-unit/%s", time.Now().String())),
|
2015-10-12 23:04:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if username := os.Getenv("ETCD_USERNAME"); username != "" {
|
2018-03-21 02:43:02 +01:00
|
|
|
config["username"] = cty.StringVal(username)
|
2015-10-12 23:04:58 +02:00
|
|
|
}
|
|
|
|
if password := os.Getenv("ETCD_PASSWORD"); password != "" {
|
2018-03-21 02:43:02 +01:00
|
|
|
config["password"] = cty.StringVal(password)
|
2015-10-12 23:04:58 +02:00
|
|
|
}
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
b := backend.TestBackendConfig(t, New(), configs.SynthBody("synth", config))
|
2018-10-01 23:35:23 +02:00
|
|
|
state, err := b.StateMgr(backend.DefaultStateName)
|
2015-10-12 23:04:58 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error for valid config: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-03-17 00:30:07 +01:00
|
|
|
remote.TestClient(t, state.(*remote.State).Client)
|
2015-10-12 23:04:58 +02:00
|
|
|
}
|