mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Cleanup 'etcd' after every test.
This commit is contained in:
parent
3c21b9c56f
commit
54dc50ec5c
@ -24,13 +24,7 @@ func TestBackend_impl(t *testing.T) {
|
|||||||
var _ backend.Backend = new(Backend)
|
var _ backend.Backend = new(Backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareEtcdv3(t *testing.T) {
|
func cleanupEtcdv3(t *testing.T) {
|
||||||
skip := os.Getenv("TF_ACC") == "" && os.Getenv("TF_ETCDV3_TEST") == ""
|
|
||||||
if skip {
|
|
||||||
t.Log("etcd server tests require setting TF_ACC or TF_ETCDV3_TEST")
|
|
||||||
t.Skip()
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := etcdv3.New(etcdv3.Config{
|
client, err := etcdv3.New(etcdv3.Config{
|
||||||
Endpoints: etcdv3Endpoints,
|
Endpoints: etcdv3Endpoints,
|
||||||
})
|
})
|
||||||
@ -42,12 +36,21 @@ func prepareEtcdv3(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Cleaned up %d keys.", res.Deleted)
|
t.Logf("Cleaned up %d keys.", res.Deleted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func prepareEtcdv3(t *testing.T) {
|
||||||
|
skip := os.Getenv("TF_ACC") == "" && os.Getenv("TF_ETCDV3_TEST") == ""
|
||||||
|
if skip {
|
||||||
|
t.Log("etcd server tests require setting TF_ACC or TF_ETCDV3_TEST")
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
|
cleanupEtcdv3(t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackend(t *testing.T) {
|
func TestBackend(t *testing.T) {
|
||||||
prepareEtcdv3(t)
|
prepareEtcdv3(t)
|
||||||
|
defer cleanupEtcdv3(t)
|
||||||
|
|
||||||
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
||||||
|
|
||||||
@ -68,6 +71,7 @@ func TestBackend(t *testing.T) {
|
|||||||
|
|
||||||
func TestBackend_lockDisabled(t *testing.T) {
|
func TestBackend_lockDisabled(t *testing.T) {
|
||||||
prepareEtcdv3(t)
|
prepareEtcdv3(t)
|
||||||
|
defer cleanupEtcdv3(t)
|
||||||
|
|
||||||
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ func TestRemoteClient_impl(t *testing.T) {
|
|||||||
|
|
||||||
func TestRemoteClient(t *testing.T) {
|
func TestRemoteClient(t *testing.T) {
|
||||||
prepareEtcdv3(t)
|
prepareEtcdv3(t)
|
||||||
|
defer cleanupEtcdv3(t)
|
||||||
|
|
||||||
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ func TestRemoteClient(t *testing.T) {
|
|||||||
|
|
||||||
func TestEtcdv3_stateLock(t *testing.T) {
|
func TestEtcdv3_stateLock(t *testing.T) {
|
||||||
prepareEtcdv3(t)
|
prepareEtcdv3(t)
|
||||||
|
defer cleanupEtcdv3(t)
|
||||||
|
|
||||||
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
||||||
|
|
||||||
@ -63,6 +65,7 @@ func TestEtcdv3_stateLock(t *testing.T) {
|
|||||||
|
|
||||||
func TestEtcdv3_destroyLock(t *testing.T) {
|
func TestEtcdv3_destroyLock(t *testing.T) {
|
||||||
prepareEtcdv3(t)
|
prepareEtcdv3(t)
|
||||||
|
defer cleanupEtcdv3(t)
|
||||||
|
|
||||||
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
prefix := fmt.Sprintf("%s/%s/", keyPrefix, time.Now().Format(time.RFC3339))
|
||||||
|
|
||||||
@ -97,10 +100,4 @@ func TestEtcdv3_destroyLock(t *testing.T) {
|
|||||||
if res.Count != 0 {
|
if res.Count != 0 {
|
||||||
t.Fatalf("lock key not cleaned up at: %s", string(res.Kvs[0].Key))
|
t.Fatalf("lock key not cleaned up at: %s", string(res.Kvs[0].Key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup leftover state.
|
|
||||||
c.Client.KV.Delete(context.TODO(), c.Key)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user