Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,34 @@ func TestAccBranchPolicyBuildValidation_basic(t *testing.T) {
})
}

func TestAccBranchPolicyBuildValidation_withoutDisplayName(t *testing.T) {
name := testutils.GenerateResourceName()
buildValidationTfNode := "azuredevops_branch_policy_build_validation.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclBuildValidationBasic(name, true, true, "", 720),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(buildValidationTfNode, "id"),
resource.TestCheckResourceAttr(buildValidationTfNode, "settings.0.display_name", ""),
),
}, {
ResourceName: buildValidationTfNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(buildValidationTfNode),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func hclBuildValidationBasic(name string, enabled, blocking bool, displayName string, validDuration int) string {
displayNameAttr := ""
if displayName != "" {
displayNameAttr = fmt.Sprintf("display_name = %q", displayName)
}
Comment on lines +64 to +67

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just accept a value (including null) in this case.

return fmt.Sprintf(`
resource "azuredevops_project" "test" {
name = "%[1]s"
Expand Down Expand Up @@ -68,7 +95,7 @@ resource "azuredevops_branch_policy_build_validation" "test" {
enabled = %[2]t
blocking = %[3]t
settings {
display_name = "%[4]s"
%[4]s
valid_duration = %[5]d
build_definition_id = azuredevops_build_definition.test.id
filename_patterns = [
Expand All @@ -82,5 +109,5 @@ resource "azuredevops_branch_policy_build_validation" "test" {
match_type = "Exact"
}
}
}`, name, enabled, blocking, displayName, validDuration)
}`, name, enabled, blocking, displayNameAttr, validDuration)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ func ResourceBranchPolicyBuildValidation() *schema.Resource {
Required: true,
},
"display_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove the validation function?

Type: schema.TypeString,
Optional: true,
},
"manual_queue_only": {
Type: schema.TypeBool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ A `settings` block supports the following:

* `build_definition_id` - (Required) The ID of the build to monitor for the policy.

* `display_name` - (Required) The display name for the policy.
* `display_name` - (Optional) The display name for the policy.

* `manual_queue_only` - (Optional) If set to true, the build will need to be manually queued. Defaults to `false`

Expand Down