@@ -3,7 +3,6 @@ package privatelinkendpointserverless_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "os"
7
6
"testing"
8
7
9
8
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -12,58 +11,44 @@ import (
12
11
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
13
12
)
14
13
15
- func TestAccServerlessPrivateLinkEndpoint_basic (t * testing.T ) {
16
- var (
17
- resourceName = "mongodbatlas_privatelink_endpoint_serverless.test"
18
- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
19
- projectName = acc .RandomProjectName ()
20
- instanceName = acc .RandomClusterName ()
21
- )
14
+ const (
15
+ resourceName = "mongodbatlas_privatelink_endpoint_serverless.test"
16
+ )
22
17
23
- resource .ParallelTest (t , resource.TestCase {
24
- PreCheck : func () { acc .PreCheckBasic (t ) },
25
- ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
26
- CheckDestroy : checkDestroy ,
27
- Steps : []resource.TestStep {
28
- {
29
- Config : configBasic (orgID , projectName , instanceName , true ),
30
- Check : resource .ComposeTestCheckFunc (
31
- checkExists (resourceName ),
32
- resource .TestCheckResourceAttr (resourceName , "instance_name" , instanceName ),
33
- ),
34
- },
35
- },
36
- })
18
+ func TestAccServerlessPrivateLinkEndpoint_basic (t * testing.T ) {
19
+ resource .ParallelTest (t , * basicTestCase (t ))
37
20
}
38
21
39
- func TestAccServerlessPrivateLinkEndpoint_importBasic (t * testing.T ) {
22
+ func basicTestCase (tb testing.TB ) * resource.TestCase {
23
+ tb .Helper ()
24
+
40
25
var (
41
- resourceName = "mongodbatlas_privatelink_endpoint_serverless.test"
42
- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
43
- projectName = acc .RandomProjectName ()
26
+ projectID = acc .ProjectIDExecution (tb )
44
27
instanceName = acc .RandomClusterName ()
45
28
)
46
- resource .ParallelTest (t , resource.TestCase {
47
- PreCheck : func () { acc .PreCheckBasic (t ) },
29
+
30
+ return & resource.TestCase {
31
+ PreCheck : func () { acc .PreCheckBasic (tb ) },
48
32
ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
49
33
CheckDestroy : checkDestroy ,
50
34
Steps : []resource.TestStep {
51
35
{
52
- Config : configBasic (orgID , projectName , instanceName , true ),
36
+ Config : configBasic (projectID , instanceName , true ),
53
37
Check : resource .ComposeTestCheckFunc (
38
+ checkExists (resourceName ),
54
39
resource .TestCheckResourceAttr (resourceName , "instance_name" , instanceName ),
55
40
),
56
41
},
57
42
{
58
- Config : configBasic (orgID , projectName , instanceName , false ),
43
+ Config : configBasic (projectID , instanceName , false ),
59
44
ResourceName : resourceName ,
60
- ImportStateIdFunc : importStateIDFuncBasic (resourceName ),
45
+ ImportStateIdFunc : importStateIDFunc (resourceName ),
61
46
ImportState : true ,
62
47
ImportStateVerify : true ,
63
48
ImportStateVerifyIgnore : []string {"connection_strings_private_endpoint_srv" },
64
49
},
65
50
},
66
- })
51
+ }
67
52
}
68
53
69
54
func checkDestroy (state * terraform.State ) error {
@@ -80,7 +65,7 @@ func checkDestroy(state *terraform.State) error {
80
65
return nil
81
66
}
82
67
83
- func configBasic (orgID , projectName , instanceName string , ignoreConnectionStrings bool ) string {
68
+ func configBasic (projectID , instanceName string , ignoreConnectionStrings bool ) string {
84
69
return fmt .Sprintf (`
85
70
86
71
resource "mongodbatlas_privatelink_endpoint_serverless" "test" {
@@ -90,7 +75,7 @@ func configBasic(orgID, projectName, instanceName string, ignoreConnectionString
90
75
}
91
76
92
77
%s
93
- ` , acc .ConfigServerlessInstanceBasic ( orgID , projectName , instanceName , ignoreConnectionStrings ))
78
+ ` , acc .ConfigServerlessInstance ( projectID , instanceName , ignoreConnectionStrings , nil , nil ))
94
79
}
95
80
96
81
func checkExists (resourceName string ) resource.TestCheckFunc {
@@ -111,7 +96,7 @@ func checkExists(resourceName string) resource.TestCheckFunc {
111
96
}
112
97
}
113
98
114
- func importStateIDFuncBasic (resourceName string ) resource.ImportStateIdFunc {
99
+ func importStateIDFunc (resourceName string ) resource.ImportStateIdFunc {
115
100
return func (s * terraform.State ) (string , error ) {
116
101
rs , ok := s .RootModule ().Resources [resourceName ]
117
102
if ! ok {
0 commit comments