Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #110
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAccDataSourceTenants(t *testing.T) { | ||
localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) | ||
name := fmt.Sprintf("data.octopusdeploy_tenants.%s", localName) | ||
skip := acctest.RandIntRange(0, 100) | ||
take := acctest.RandIntRange(0, 100) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckTenantsDataSourceID(name), | ||
resource.TestCheckResourceAttrSet(name, "id"), | ||
resource.TestCheckResourceAttr(name, "skip", strconv.Itoa(skip)), | ||
resource.TestCheckResourceAttr(name, "take", strconv.Itoa(take)), | ||
), | ||
Config: testAccDataSourceTenantsConfig(localName, skip, take), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckTenantsDataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
all := s.RootModule().Resources | ||
rs, ok := all[n] | ||
if !ok { | ||
return fmt.Errorf("cannot find tenants data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("snapshot tenants source ID not set") | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func testAccDataSourceTenantsConfig(localName string, skip int, take int) string { | ||
return fmt.Sprintf(`data "octopusdeploy_tenants" "%s" { | ||
skip = %v | ||
take = %v | ||
}`, localName, skip, take) | ||
} |