github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/backend/remote-state/etcdv2/client_test.go (about) 1 package etcdv2 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 "time" 8 9 "github.com/hashicorp/terraform/backend" 10 "github.com/hashicorp/terraform/configs" 11 "github.com/hashicorp/terraform/state/remote" 12 "github.com/zclconf/go-cty/cty" 13 ) 14 15 func TestEtcdClient_impl(t *testing.T) { 16 var _ remote.Client = new(EtcdClient) 17 } 18 19 func TestEtcdClient(t *testing.T) { 20 endpoint := os.Getenv("ETCD_ENDPOINT") 21 if endpoint == "" { 22 t.Skipf("skipping; ETCD_ENDPOINT must be set") 23 } 24 25 // Get the backend 26 config := map[string]cty.Value{ 27 "endpoints": cty.StringVal(endpoint), 28 "path": cty.StringVal(fmt.Sprintf("tf-unit/%s", time.Now().String())), 29 } 30 31 if username := os.Getenv("ETCD_USERNAME"); username != "" { 32 config["username"] = cty.StringVal(username) 33 } 34 if password := os.Getenv("ETCD_PASSWORD"); password != "" { 35 config["password"] = cty.StringVal(password) 36 } 37 38 b := backend.TestBackendConfig(t, New(), configs.SynthBody("synth", config)) 39 state, err := b.StateMgr(backend.DefaultStateName) 40 if err != nil { 41 t.Fatalf("Error for valid config: %s", err) 42 } 43 44 remote.TestClient(t, state.(*remote.State).Client) 45 }