Skip to content

Commit 5d740fd

Browse files
committed
Use new test helper instead of custom one
1 parent 72ae7de commit 5d740fd

File tree

4 files changed

+63
-18
lines changed

4 files changed

+63
-18
lines changed

internal/provider/helper_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14-
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1514
"github.com/onsi/gomega"
1615
"github.com/xanzy/go-gitlab"
1716
)
@@ -455,14 +454,6 @@ func testAccGitlabProjectStart(t *testing.T) testAccGitlabProjectContext {
455454
}
456455
}
457456

458-
// testCheckResourceAttrLazy works like resource.TestCheckResourceAttr, but lazy evaluates the value parameter.
459-
// See also: resource.TestCheckResourceAttrPtr.
460-
func testCheckResourceAttrLazy(name string, key string, value func() string) resource.TestCheckFunc {
461-
return func(s *terraform.State) error {
462-
return resource.TestCheckResourceAttr(name, key, value())(s)
463-
}
464-
}
465-
466457
func copyFile(src, dst string) error {
467458
in, err := os.Open(src)
468459
if err != nil {

internal/provider/resource_gitlab_project_environment_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ func TestAccGitlabProjectEnvironment_basic(t *testing.T) {
4242
Name: fmt.Sprintf("ProjectEnvironment-%d", rInt),
4343
State: "available",
4444
}),
45-
testCheckResourceAttrLazy("gitlab_project_environment.this", "created_at", func() string { return env1.CreatedAt.Format(time.RFC3339) }),
45+
resource.TestCheckResourceAttrWith("gitlab_project_environment.this", "created_at", func(value string) error {
46+
expectedValue := env1.CreatedAt.Format(time.RFC3339)
47+
if value != expectedValue {
48+
return fmt.Errorf("should be equal to %s", expectedValue)
49+
}
50+
return nil
51+
}),
4652
),
4753
},
4854
// Verify import
@@ -62,8 +68,20 @@ func TestAccGitlabProjectEnvironment_basic(t *testing.T) {
6268
State: "available",
6369
ExternalURL: "https://example.com",
6470
}),
65-
testCheckResourceAttrLazy("gitlab_project_environment.this", "created_at", func() string { return env2.CreatedAt.Format(time.RFC3339) }),
66-
testCheckResourceAttrLazy("gitlab_project_environment.this", "updated_at", func() string { return env2.UpdatedAt.Format(time.RFC3339) }),
71+
resource.TestCheckResourceAttrWith("gitlab_project_environment.this", "created_at", func(value string) error {
72+
expectedValue := env2.CreatedAt.Format(time.RFC3339)
73+
if value != expectedValue {
74+
return fmt.Errorf("should be equal to %s", expectedValue)
75+
}
76+
return nil
77+
}),
78+
resource.TestCheckResourceAttrWith("gitlab_project_environment.this", "updated_at", func(value string) error {
79+
expectedValue := env2.UpdatedAt.Format(time.RFC3339)
80+
if value != expectedValue {
81+
return fmt.Errorf("should be equal to %s", expectedValue)
82+
}
83+
return nil
84+
}),
6785
),
6886
},
6987
// Verify import

internal/provider/resource_gitlab_project_issue_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ func TestAccGitlabProjectIssue_basic(t *testing.T) {
4040
resource.TestCheckResourceAttr("gitlab_project_issue.this", "project", testProject.PathWithNamespace),
4141
resource.TestCheckResourceAttr("gitlab_project_issue.this", "iid", "1"),
4242
resource.TestCheckResourceAttr("gitlab_project_issue.this", "title", "Terraform test issue"),
43-
testCheckResourceAttrLazy("gitlab_project_issue.this", "created_at", func() string { return testIssue.CreatedAt.Format(time.RFC3339) }),
43+
resource.TestCheckResourceAttrWith("gitlab_project_issue.this", "created_at", func(value string) error {
44+
expectedValue := testIssue.CreatedAt.Format(time.RFC3339)
45+
if value != expectedValue {
46+
return fmt.Errorf("should be equal to %s", expectedValue)
47+
}
48+
return nil
49+
}),
4450
),
4551
},
4652
// Verify import
@@ -58,7 +64,13 @@ func TestAccGitlabProjectIssue_basic(t *testing.T) {
5864
resource.TestCheckResourceAttr("gitlab_project_issue.this", "project", testProject.PathWithNamespace),
5965
resource.TestCheckResourceAttr("gitlab_project_issue.this", "iid", "1"),
6066
resource.TestCheckResourceAttr("gitlab_project_issue.this", "title", "Terraform test issue"),
61-
testCheckResourceAttrLazy("gitlab_project_issue.this", "updated_at", func() string { return updatedTestIssue.UpdatedAt.Format(time.RFC3339) }),
67+
resource.TestCheckResourceAttrWith("gitlab_project_issue.this", "updated_at", func(value string) error {
68+
expectedValue := updatedTestIssue.UpdatedAt.Format(time.RFC3339)
69+
if value != expectedValue {
70+
return fmt.Errorf("should be equal to %s", expectedValue)
71+
}
72+
return nil
73+
}),
6274
),
6375
},
6476
// Verify import
@@ -97,7 +109,13 @@ func TestAccGitlabProjectIssue_basic(t *testing.T) {
97109
Check: resource.ComposeTestCheckFunc(
98110
testAccCheckGitlabProjectIssueExists("gitlab_project_issue.this", &testIssue),
99111
resource.TestCheckResourceAttr("gitlab_project_issue.this", "state", "closed"),
100-
testCheckResourceAttrLazy("gitlab_project_issue.this", "closed_at", func() string { return testIssue.ClosedAt.Format(time.RFC3339) }),
112+
resource.TestCheckResourceAttrWith("gitlab_project_issue.this", "closed_at", func(value string) error {
113+
expectedValue := testIssue.ClosedAt.Format(time.RFC3339)
114+
if value != expectedValue {
115+
return fmt.Errorf("should be equal to %s", expectedValue)
116+
}
117+
return nil
118+
}),
101119
resource.TestCheckResourceAttr("gitlab_project_issue.this", "closed_by_user_id", fmt.Sprintf("%d", currentUser.ID)),
102120
),
103121
},

internal/provider/resource_gitlab_service_external_wiki_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ func TestAccGitlabServiceExternalWiki_basic(t *testing.T) {
3434
resource.TestCheckResourceAttr(externalWikiResourceName, "external_wiki_url", externalWikiURL1),
3535
resource.TestCheckResourceAttr(externalWikiResourceName, "external_wiki_url", externalWikiURL1),
3636
resource.TestCheckResourceAttr(externalWikiResourceName, "active", "true"),
37-
testCheckResourceAttrLazy(externalWikiResourceName, "created_at", func() string { return externalWikiService.CreatedAt.Format(time.RFC3339) }),
37+
resource.TestCheckResourceAttrWith(externalWikiResourceName, "created_at", func(value string) error {
38+
expectedValue := externalWikiService.CreatedAt.Format(time.RFC3339)
39+
if value != expectedValue {
40+
return fmt.Errorf("should be equal to %s", expectedValue)
41+
}
42+
return nil
43+
}),
3844
),
3945
},
4046
// Verify import
@@ -49,8 +55,20 @@ func TestAccGitlabServiceExternalWiki_basic(t *testing.T) {
4955
Check: resource.ComposeTestCheckFunc(
5056
testAccCheckGitlabServiceExternalWikiExists(externalWikiResourceName, &externalWikiService),
5157
resource.TestCheckResourceAttr(externalWikiResourceName, "external_wiki_url", externalWikiURL2),
52-
testCheckResourceAttrLazy(externalWikiResourceName, "created_at", func() string { return externalWikiService.CreatedAt.Format(time.RFC3339) }),
53-
testCheckResourceAttrLazy(externalWikiResourceName, "updated_at", func() string { return externalWikiService.UpdatedAt.Format(time.RFC3339) }),
58+
resource.TestCheckResourceAttrWith(externalWikiResourceName, "created_at", func(value string) error {
59+
expectedValue := externalWikiService.CreatedAt.Format(time.RFC3339)
60+
if value != expectedValue {
61+
return fmt.Errorf("should be equal to %s", expectedValue)
62+
}
63+
return nil
64+
}),
65+
resource.TestCheckResourceAttrWith(externalWikiResourceName, "updated_at", func(value string) error {
66+
expectedValue := externalWikiService.UpdatedAt.Format(time.RFC3339)
67+
if value != expectedValue {
68+
return fmt.Errorf("should be equal to %s", expectedValue)
69+
}
70+
return nil
71+
}),
5472
),
5573
},
5674
// Verify import

0 commit comments

Comments
 (0)