Skip to content

Commit 81ad65c

Browse files
maded tests generic and dependent on env var
1 parent 4060a6a commit 81ad65c

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package provider
22

33
import (
4-
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
5-
"github.com/hashicorp/terraform-plugin-testing/echoprovider"
4+
"os"
65
"testing"
76

7+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
8+
"github.com/hashicorp/terraform-plugin-testing/echoprovider"
89
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
910
)
1011

1112
func TestAccTFEHYOKCustomerKeyVersionDataSource_basic(t *testing.T) {
13+
hyokCustomerKeyVersionId := os.Getenv("HYOK_CUSTOMER_KEY_VERSION_ID")
14+
if hyokCustomerKeyVersionId == "" {
15+
t.Skip("HYOK_CUSTOMER_KEY_VERSION_ID environment variable must be set to run this test")
16+
}
17+
1218
resource.Test(t, resource.TestCase{
1319
PreCheck: func() { testAccPreCheck(t) },
1420
ProtoV5ProviderFactories: testAccMuxedProviders,
@@ -17,11 +23,11 @@ func TestAccTFEHYOKCustomerKeyVersionDataSource_basic(t *testing.T) {
1723
},
1824
Steps: []resource.TestStep{
1925
{
20-
Config: testAccTFEHYOKCustomerKeyVersionDataSourceConfig,
26+
Config: testAccTFEHYOKCustomerKeyVersionDataSourceConfig(hyokCustomerKeyVersionId),
2127
Check: resource.ComposeAggregateTestCheckFunc(
22-
resource.TestCheckResourceAttr("data.tfe_hyok_customer_key_version.test", "id", "keyv-BWZTzt2J75DsdwH8"),
23-
resource.TestCheckResourceAttr("data.tfe_hyok_customer_key_version.test", "status", "available"),
24-
resource.TestCheckResourceAttr("data.tfe_hyok_customer_key_version.test", "key_version", "10"),
28+
resource.TestCheckResourceAttr("data.tfe_hyok_customer_key_version.test", "id", hyokCustomerKeyVersionId),
29+
resource.TestCheckResourceAttrSet("data.tfe_hyok_customer_key_version.test", "status"),
30+
resource.TestCheckResourceAttrSet("data.tfe_hyok_customer_key_version.test", "key_version"),
2531
resource.TestCheckResourceAttrSet("data.tfe_hyok_customer_key_version.test", "created_at"),
2632
resource.TestCheckResourceAttrSet("data.tfe_hyok_customer_key_version.test", "updated_at"),
2733
),
@@ -30,12 +36,10 @@ func TestAccTFEHYOKCustomerKeyVersionDataSource_basic(t *testing.T) {
3036
})
3137
}
3238

33-
const testAccTFEHYOKCustomerKeyVersionDataSourceConfig = `
34-
data "tfe_organization" "org" {
35-
name = "dretli-hyok-org"
36-
}
37-
39+
func testAccTFEHYOKCustomerKeyVersionDataSourceConfig(id string) string {
40+
return `
3841
data "tfe_hyok_customer_key_version" "test" {
39-
id = "keyv-BWZTzt2J75DsdwH8"
42+
id = "` + id + `"
4043
}
4144
`
45+
}
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package provider
22

33
import (
4-
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
5-
"github.com/hashicorp/terraform-plugin-testing/echoprovider"
4+
"os"
65
"testing"
76

7+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
8+
"github.com/hashicorp/terraform-plugin-testing/echoprovider"
89
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
910
)
1011

1112
func TestAccTFEHYOKEncryptedDataKeyDataSource_basic(t *testing.T) {
13+
hyokEncryptedDataKeyID := os.Getenv("HYOK_ENCRYPTED_DATA_KEY_ID")
14+
if hyokEncryptedDataKeyID == "" {
15+
t.Skip("HYOK_ENCRYPTED_DATA_KEY_ID environment variable must be set to run this test")
16+
}
17+
1218
resource.Test(t, resource.TestCase{
1319
PreCheck: func() { testAccPreCheck(t) },
1420
ProtoV5ProviderFactories: testAccMuxedProviders,
@@ -17,24 +23,22 @@ func TestAccTFEHYOKEncryptedDataKeyDataSource_basic(t *testing.T) {
1723
},
1824
Steps: []resource.TestStep{
1925
{
20-
Config: testAccTFEHYOKEncryptedDataKeyDataSourceConfig,
26+
Config: testAccTFEHYOKEncryptedDataKeyDataSourceConfig(hyokEncryptedDataKeyID),
2127
Check: resource.ComposeAggregateTestCheckFunc(
22-
resource.TestCheckResourceAttr("data.tfe_hyok_encrypted_data_key.test", "id", "dek-wuLiejfGtNLLuiH9"),
23-
resource.TestCheckResourceAttr("data.tfe_hyok_encrypted_data_key.test", "encrypted_dek", "dmF1bHQ6djEwOjdFb3gzNERXQ05zNGVNelNSb09waWp3dGE4SmlNa0JjWFRsQ25KbXlRNlZWRGpCbnFtOFBvbGkvb1ZGTkQ3UVFybDNoNzBrT2hScnlHUlZS"),
24-
resource.TestCheckResourceAttr("data.tfe_hyok_encrypted_data_key.test", "customer_key_name", "tf-rocket-hyok-oasis"),
28+
resource.TestCheckResourceAttr("data.tfe_hyok_encrypted_data_key.test", "id", hyokEncryptedDataKeyID),
29+
resource.TestCheckResourceAttrSet("data.tfe_hyok_encrypted_data_key.test", "encrypted_dek"),
30+
resource.TestCheckResourceAttrSet("data.tfe_hyok_encrypted_data_key.test", "customer_key_name"),
2531
resource.TestCheckResourceAttrSet("data.tfe_hyok_encrypted_data_key.test", "created_at"),
2632
),
2733
},
2834
},
2935
})
3036
}
3137

32-
const testAccTFEHYOKEncryptedDataKeyDataSourceConfig = `
33-
data "tfe_organization" "org" {
34-
name = "dretli-hyok-org"
35-
}
36-
38+
func testAccTFEHYOKEncryptedDataKeyDataSourceConfig(id string) string {
39+
return `
3740
data "tfe_hyok_encrypted_data_key" "test" {
38-
id = "dek-wuLiejfGtNLLuiH9"
41+
id = "` + id + `"
3942
}
4043
`
44+
}

0 commit comments

Comments
 (0)