Skip to content

Commit

Permalink
Added tenants data source testing
Browse files Browse the repository at this point in the history
Closes #110
  • Loading branch information
jbristowe committed Jan 13, 2021
1 parent 1670895 commit f1cfaab
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions octopusdeploy/data_source_tenants_test.go
@@ -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)
}

0 comments on commit f1cfaab

Please sign in to comment.