-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathdata_source_mongodbatlas_api_keys_test.go
56 lines (48 loc) · 1.71 KB
/
data_source_mongodbatlas_api_keys_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package mongodbatlas
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccConfigDSAPIKeys_basic(t *testing.T) {
resourceName := "mongodbatlas_api_key.test"
dataSourceName := "data.mongodbatlas_api_keys.test"
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
description := fmt.Sprintf("test-acc-api_key-%s", acctest.RandString(5))
roleName := "ORG_MEMBER"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAPIKeysConfig(orgID, description, roleName),
Check: resource.ComposeTestCheckFunc(
// Test for Resource
testAccCheckMongoDBAtlasAPIKeyExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "org_id"),
resource.TestCheckResourceAttrSet(resourceName, "description"),
resource.TestCheckResourceAttr(resourceName, "org_id", orgID),
resource.TestCheckResourceAttr(resourceName, "description", description),
// Test for Data source
resource.TestCheckResourceAttrSet(dataSourceName, "org_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.#"),
),
},
},
})
}
func testAccDSMongoDBAtlasAPIKeysConfig(orgID, description, roleNames string) string {
return fmt.Sprintf(`
resource "mongodbatlas_api_key" "test" {
org_id = "%s"
description = "%s"
role_names = ["%s"]
}
data "mongodbatlas_api_keys" "test" {
org_id = "${mongodbatlas_api_key.test.org_id}"
}
`, orgID, description, roleNames)
}