Skip to content

Commit f189cfa

Browse files
committed
chore: fix tests
1 parent 0494d77 commit f189cfa

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

octopusdeploy/test_helpers_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package octopusdeploy
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
7+
)
8+
9+
// testAccProjectGroup creates a project group configuration for testing
10+
func testAccProjectGroup(localName string, name string) string {
11+
return fmt.Sprintf(`resource "octopusdeploy_project_group" "%s" {
12+
name = "%s"
13+
}`, localName, name)
14+
}
15+
16+
// testAccProjectGroupCheckDestroy checks that all project groups have been destroyed
17+
func testAccProjectGroupCheckDestroy(s *terraform.State) error {
18+
for _, rs := range s.RootModule().Resources {
19+
if rs.Type != "octopusdeploy_project_group" {
20+
continue
21+
}
22+
23+
if projectGroup, err := octoClient.ProjectGroups.GetByID(rs.Primary.ID); err == nil {
24+
return fmt.Errorf("project group (%s) still exists", projectGroup.GetID())
25+
}
26+
}
27+
28+
return nil
29+
}
30+
31+
// testAwsAccount creates an AWS account configuration for testing
32+
func testAwsAccount(localName string, name string, accessKey string, secretKey string) string {
33+
return fmt.Sprintf(`resource "octopusdeploy_aws_account" "%s" {
34+
access_key = "%s"
35+
name = "%s"
36+
secret_key = "%s"
37+
}`, localName, accessKey, name, secretKey)
38+
}

octopusdeploy_framework/resource_project_group_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAccOctopusDeployProjectGroupBasic(t *testing.T) {
2424
Steps: []resource.TestStep{
2525
{
2626
Check: resource.ComposeTestCheckFunc(
27-
testProjectGroupExists(prefix),
27+
testOctopusDeployProjectGroupExists(prefix),
2828
resource.TestCheckResourceAttrSet(prefix, "id"),
2929
resource.TestCheckResourceAttr(prefix, "name", name),
3030
resource.TestCheckResourceAttr(prefix, "description", description),
@@ -53,15 +53,15 @@ func TestAccOctopusDeployProjectGroupUpdate(t *testing.T) {
5353
Steps: []resource.TestStep{
5454
{
5555
Check: resource.ComposeTestCheckFunc(
56-
testProjectGroupExists(prefix),
56+
testOctopusDeployProjectGroupExists(prefix),
5757
resource.TestCheckResourceAttr(prefix, "name", name),
5858
resource.TestCheckResourceAttr(prefix, "description", description),
5959
),
6060
Config: testProjectGroupBasic(localName, name, description),
6161
},
6262
{
6363
Check: resource.ComposeTestCheckFunc(
64-
testProjectGroupExists(prefix),
64+
testOctopusDeployProjectGroupExists(prefix),
6565
resource.TestCheckResourceAttr(prefix, "name", newName),
6666
resource.TestCheckResourceAttr(prefix, "description", newDescription),
6767
),
@@ -84,7 +84,7 @@ func TestAccOctopusDeployProjectGroupMinimal(t *testing.T) {
8484
Steps: []resource.TestStep{
8585
{
8686
Check: resource.ComposeTestCheckFunc(
87-
testProjectGroupExists(prefix),
87+
testOctopusDeployProjectGroupExists(prefix),
8888
resource.TestCheckResourceAttrSet(prefix, "id"),
8989
resource.TestCheckResourceAttr(prefix, "name", name),
9090
resource.TestCheckResourceAttr(prefix, "description", ""),
@@ -136,7 +136,7 @@ func testProjectGroupMinimal(localName string, name string) string {
136136
}`, localName, name)
137137
}
138138

139-
func testProjectGroupExists(resourceName string) resource.TestCheckFunc {
139+
func testOctopusDeployProjectGroupExists(resourceName string) resource.TestCheckFunc {
140140
return func(s *terraform.State) error {
141141
rs, ok := s.RootModule().Resources[resourceName]
142142
if !ok {

0 commit comments

Comments
 (0)