Skip to content

Commit 2a92f73

Browse files
committed
Restore lost functions in rebase.
1 parent 69a5870 commit 2a92f73

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

codefresh/internal/acctestutil/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package acctestutil provides utilities for Terraform acceptance tests.
2+
package acctestutil
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package acctestutil
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
7+
)
8+
9+
// TestAccGetResourceId returns the ID of the resource with the given name,
10+
// when provided with the Terraform state.
11+
//
12+
// This is useful for acceptance tests, in order to verify that a resource has
13+
// been recreated and hence its ID has changed.
14+
func GetResourceId(s *terraform.State, resourceName string) (string, error) {
15+
rs, ok := s.RootModule().Resources[resourceName]
16+
if !ok {
17+
return "", fmt.Errorf("resource %s not found", resourceName)
18+
}
19+
return rs.Primary.ID, nil
20+
}

codefresh/resource_account_user_association_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"fmt"
55
"testing"
66

7-
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
7+
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
8+
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/acctestutil"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
@@ -16,7 +17,7 @@ func testAccCodefreshAccountUserAssociationGenerateUserEmail() string {
1617
}
1718

1819
func testAccCodefreshActivateUser(s *terraform.State, email string) error {
19-
c := testAccProvider.Meta().(*cfClient.Client)
20+
c := testAccProvider.Meta().(*cfclient.Client)
2021
currentAccount, err := c.GetCurrentAccount()
2122
if err != nil {
2223
return fmt.Errorf("failed to get current account: %s", err)
@@ -94,7 +95,7 @@ func TestAccCodefreshAccountUserAssociation_StatusPending_Email_ForceNew(t *test
9495
{
9596
RefreshState: true,
9697
Check: func(s *terraform.State) error {
97-
resourceId, err = testAccGetResourceId(s, resourceName)
98+
resourceId, err = acctestutil.GetResourceId(s, resourceName)
9899
return err
99100
},
100101
},
@@ -110,7 +111,7 @@ func TestAccCodefreshAccountUserAssociation_StatusPending_Email_ForceNew(t *test
110111
// Test that an email change on a pending user does NOT force a new resource
111112
RefreshState: true,
112113
Check: func(s *terraform.State) error {
113-
newResourceId, err := testAccGetResourceId(s, resourceName)
114+
newResourceId, err := acctestutil.GetResourceId(s, resourceName)
114115
if err != nil {
115116
return err
116117
}
@@ -147,7 +148,7 @@ func TestAccCodefreshAccountUserAssociation_StatusNew_Email_ForceNew(t *testing.
147148
{
148149
RefreshState: true,
149150
Check: func(s *terraform.State) error {
150-
resourceId, err = testAccGetResourceId(s, resourceName)
151+
resourceId, err = acctestutil.GetResourceId(s, resourceName)
151152
return err
152153
},
153154
},
@@ -169,7 +170,7 @@ func TestAccCodefreshAccountUserAssociation_StatusNew_Email_ForceNew(t *testing.
169170
{
170171
RefreshState: true,
171172
Check: func(s *terraform.State) error {
172-
newResourceId, err := testAccGetResourceId(s, resourceName)
173+
newResourceId, err := acctestutil.GetResourceId(s, resourceName)
173174
if err != nil {
174175
return err
175176
}

0 commit comments

Comments
 (0)