Skip to content

Commit b1c87a5

Browse files
committed
fix data race for the API key acc. tests
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
1 parent 003d25e commit b1c87a5

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

provider/acc-orgapikey_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"slices"
77
"testing"
88

9+
"github.com/google/uuid"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
@@ -27,7 +28,7 @@ func TestAccOrgAPIKeys(t *testing.T) {
2728
t.Fatal(err)
2829
}
2930

30-
wantKeyName := projectNamePrefix + "orgApikey"
31+
wantKeyName := projectNamePrefix + "orgApikey" + uuid.NewString()
3132

3233
t.Cleanup(func() {
3334
keys, _ := client.ListOrgApiKeys(orgID)

provider/acc_api_key_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package provider
33
import (
44
"fmt"
55
"os"
6+
"strings"
67
"testing"
78

9+
"github.com/google/uuid"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1012
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
@@ -41,8 +43,24 @@ func TestRecreateAPIKeyIfNotFound(t *testing.T) {
4143

4244
}
4345

46+
t.Cleanup(func() {
47+
ref, err := client.ListApiKeys()
48+
if err != nil {
49+
panic(err)
50+
}
51+
52+
for _, key := range ref {
53+
if strings.HasPrefix(key.Name, "test") {
54+
_, err = client.RevokeApiKey(key.ID)
55+
if err != nil {
56+
panic(err)
57+
}
58+
}
59+
}
60+
})
61+
4462
t.Run("shall indicate non empty plan if the API key was deleted outside of terraform", func(t *testing.T) {
45-
keyName := "test"
63+
keyName := "test" + uuid.NewString()
4664
resource.Test(
4765
t, resource.TestCase{
4866
ProviderFactories: map[string]func() (*schema.Provider, error){
@@ -72,7 +90,7 @@ func TestRecreateAPIKeyIfNotFound(t *testing.T) {
7290
})
7391

7492
t.Run("shall destroy even if the API key was deleted outside of terraform,", func(t *testing.T) {
75-
keyName := "test"
93+
keyName := "test" + uuid.NewString()
7694
config := fmt.Sprintf(`resource "neon_api_key" "this" {name = "%s"}`, keyName)
7795
resource.Test(
7896
t, resource.TestCase{

0 commit comments

Comments
 (0)