Skip to content

Commit

Permalink
Updated job collection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed Mar 13, 2018
1 parent 7bf15d8 commit 790b30c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion azurerm/resource_arm_scheduler_job_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func resourceArmSchedulerJobCollectionPopulate(d *schema.ResourceData, resourceG
d.Set("state", string(properties.State))

if err := d.Set("quota", flattenAzureArmSchedulerJobCollectionQuota(properties.Quota)); err != nil {
return fmt.Errorf("Error flattening quoto for Job Collection %q (Resource Group %q): %+v", collection.Name, resourceGroup, err)
return fmt.Errorf("Error flattening quota for Job Collection %q (Resource Group %q): %+v", collection.Name, resourceGroup, err)
}
}

Expand Down
63 changes: 41 additions & 22 deletions azurerm/resource_arm_scheduler_job_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/scheduler/mgmt/2016-03-01/scheduler"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand All @@ -13,7 +14,7 @@ import (
func TestAccAzureRMSchedulerJobCollection_basic(t *testing.T) {
ri := acctest.RandInt()
resourceName := "azurerm_scheduler_job_collection.test"
config := testAccAzureRMSchedulerJobCollection(ri, testLocation(), "")
config := testAccAzureRMSchedulerJobCollection_basic(ri, testLocation(), "")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -25,6 +26,7 @@ func TestAccAzureRMSchedulerJobCollection_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSchedulerJobCollectionExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Enabled)),
),
},
},
Expand All @@ -34,25 +36,31 @@ func TestAccAzureRMSchedulerJobCollection_basic(t *testing.T) {
func TestAccAzureRMSchedulerJobCollection_complete(t *testing.T) {
ri := acctest.RandInt()
resourceName := "azurerm_scheduler_job_collection.test"
config := testAccAzureRMSchedulerJobCollection(ri, testLocation(), `
state = "disabled"
quota {
max_recurrence_frequency = "hour"
max_retry_interval = 10
max_job_count = 10
}
`)
preConfig := testAccAzureRMSchedulerJobCollection_basic(ri, testLocation(), "")
config := testAccAzureRMSchedulerJobCollection_complete(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSchedulerJobCollectionDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSchedulerJobCollectionExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Enabled)),
),
},
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSchedulerJobCollectionExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Disabled)),
resource.TestCheckResourceAttr(resourceName, "quota.0.max_job_count", "10"),
resource.TestCheckResourceAttr(resourceName, "quota.0.max_retry_interval", "10"),
resource.TestCheckResourceAttr(resourceName, "quota.0.max_recurrence_frequency", string(scheduler.Hour)),
),
},
},
Expand Down Expand Up @@ -117,19 +125,30 @@ func testCheckAzureRMSchedulerJobCollectionExists(name string) resource.TestChec
}
}

func testAccAzureRMSchedulerJobCollection(rInt int, location string, additional string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
func testAccAzureRMSchedulerJobCollection_basic(rInt int, location string, additional string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_scheduler_job_collection" "test" {
name = "acctest-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
%s
}
`, rInt, location, rInt, additional)
}

resource "azurerm_scheduler_job_collection" "test" {
name = "acctest-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
%s
}
`, rInt, location, rInt, additional)
func testAccAzureRMSchedulerJobCollection_complete(rInt int, location string) string {
return testAccAzureRMSchedulerJobCollection_basic(rInt, location, `
state = "disabled"
quota {
max_recurrence_frequency = "hour"
max_retry_interval = 10
max_job_count = 10
}
`)
}

0 comments on commit 790b30c

Please sign in to comment.