Skip to content

Commit

Permalink
Merge pull request microsoft#436 from xuzhang3/f/repo_policy
Browse files Browse the repository at this point in the history
Repository policy
  • Loading branch information
xuzhang3 authored Aug 23, 2021
2 parents 2e1367c + e6977d5 commit 73a5975
Show file tree
Hide file tree
Showing 27 changed files with 1,700 additions and 204 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build all resource_repositorypolicy_author_email_patterns
// +build !exclude_serviceendpoints
// +build !resource_repositorypolicy_author_email_patterns

package acceptancetests

Expand Down Expand Up @@ -37,7 +37,7 @@ func testAccRepositoryPolicyAuthorEmailPatternsRepoPolicyBasic(t *testing.T) {
Config: hclRepositoryPolicyAuthorEmailPatternsResourceRepoPolicyBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(authorEmailTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.#", "1"),
resource.TestCheckResourceAttr(authorEmailTfNode, "author_email_patterns.0", "test1@test.com"),
),
}, {
ResourceName: authorEmailTfNode,
Expand All @@ -62,14 +62,12 @@ func testAccRepositoryPolicyAuthorEmailPatternsRepoPolicyUpdate(t *testing.T) {
Config: hclRepositoryPolicyAuthorEmailPatternsResourceRepoPolicyBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(authorEmailTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.#", "1"),
),
}, {
Config: hclRepositoryPolicyAuthorEmailPatternsResourceRepoPolicyUpdate(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.0.author_email_patterns.#", "2"),
resource.TestCheckResourceAttr(authorEmailTfNode, "author_email_patterns.0", "test2@test.com"),
resource.TestCheckResourceAttr(authorEmailTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.#", "1"),
),
}, {
ResourceName: authorEmailTfNode,
Expand All @@ -94,7 +92,7 @@ func testAccRepositoryPolicyAuthorEmailPatternsProjectPolicyBasic(t *testing.T)
Config: hclRepositoryPolicyAuthorEmailPatternsResourceProjectPolicyBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(authorEmailTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.#", "1"),
resource.TestCheckResourceAttr(authorEmailTfNode, "author_email_patterns.#", "1"),
),
}, {
ResourceName: authorEmailTfNode,
Expand All @@ -119,14 +117,12 @@ func testAccRepositoryPolicyAuthorEmailPatternsProjectPolicyUpdate(t *testing.T)
Config: hclRepositoryPolicyAuthorEmailPatternsResourceProjectPolicyBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(authorEmailTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.#", "1"),
),
}, {
Config: hclRepositoryPolicyAuthorEmailPatternsResourceProjectPolicyUpdate(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.0.author_email_patterns.#", "2"),
resource.TestCheckResourceAttr(authorEmailTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(authorEmailTfNode, "settings.#", "1"),
resource.TestCheckResourceAttr(authorEmailTfNode, "author_email_patterns.#", "2"),
),
}, {
ResourceName: authorEmailTfNode,
Expand Down Expand Up @@ -167,12 +163,8 @@ resource "azuredevops_repository_policy_author_email_pattern" "p" {
enabled = true
blocking = true
settings {
author_email_patterns = ["test1@test.com"]
scope {
repository_id = azuredevops_git_repository.r.id
}
}
author_email_patterns = ["test1@test.com"]
repository_ids = [azuredevops_git_repository.r.id]
}
`)
}
Expand All @@ -186,12 +178,8 @@ resource "azuredevops_repository_policy_author_email_pattern" "p" {
enabled = true
blocking = true
settings {
author_email_patterns = ["test1@test.com", "test2@test.com"]
scope {
repository_id = azuredevops_git_repository.r.id
}
}
author_email_patterns = ["test2@test.com"]
repository_ids = [azuredevops_git_repository.r.id]
}
`)
}
Expand All @@ -204,11 +192,8 @@ resource "azuredevops_repository_policy_author_email_pattern" "p" {
enabled = true
blocking = true
settings {
author_email_patterns = ["test1@test.com"]
}
depends_on = [azuredevops_git_repository.r]
author_email_patterns = ["test1@test.com"]
depends_on = [azuredevops_git_repository.r]
}
`)
}
Expand All @@ -222,9 +207,7 @@ resource "azuredevops_repository_policy_author_email_pattern" "p" {
enabled = true
blocking = true
settings {
author_email_patterns = ["test1@test.com", "test2@test.com"]
}
author_email_patterns = ["test1@test.com", "test2@test.com"]
depends_on = [azuredevops_git_repository.r]
}
`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
// +build all resource_policy_case_enforcement
// +build !resource_policy_case_enforcement

package acceptancetests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)

const caseEnforceTfNode = "azuredevops_repository_policy_case_enforcement.p"

func TestAccPolicyCaseEnforcement(t *testing.T) {
testutils.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){
"RepositoryPolicies": {
"basic": testAccRepoPolicyEnforceConsistentCaseBasic,
"update": testAccRepoPolicyEnforceConsistentCaseUpdate,
},
"ProjectPolicies": {
"basic": testAccProjectPolicyEnforceConsistentCaseBasic,
"update": testAccProjectPolicyEnforceConsistentCaseUpdate,
},
})
}

func testAccRepoPolicyEnforceConsistentCaseBasic(t *testing.T) {
projectName := testutils.GenerateResourceName()
repoName := testutils.GenerateResourceName()

resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclRepoPolicyEnforceConsistentCaseBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(caseEnforceTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(caseEnforceTfNode, "enforce_consistent_case", "true"),
),
}, {
ResourceName: caseEnforceTfNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(caseEnforceTfNode),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccRepoPolicyEnforceConsistentCaseUpdate(t *testing.T) {
projectName := testutils.GenerateResourceName()
repoName := testutils.GenerateResourceName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclRepoPolicyEnforceConsistentCaseBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(caseEnforceTfNode, "enabled", "true"),
),
}, {
Config: hclRepoPolicyEnforceConsistentCaseUpdate(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(caseEnforceTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(caseEnforceTfNode, "enforce_consistent_case", "false"),
),
}, {
ResourceName: caseEnforceTfNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(caseEnforceTfNode),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccProjectPolicyEnforceConsistentCaseBasic(t *testing.T) {
projectName := testutils.GenerateResourceName()
repoName := testutils.GenerateResourceName()

resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclProjectPolicyEnforceConsistentCaseBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(caseEnforceTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(caseEnforceTfNode, "enforce_consistent_case", "true"),
),
}, {
ResourceName: caseEnforceTfNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(caseEnforceTfNode),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccProjectPolicyEnforceConsistentCaseUpdate(t *testing.T) {
projectName := testutils.GenerateResourceName()
repoName := testutils.GenerateResourceName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclProjectPolicyEnforceConsistentCaseBasic(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(caseEnforceTfNode, "enabled", "true"),
),
}, {
Config: hclProjectPolicyEnforceConsistentCaseUpdate(projectName, repoName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(caseEnforceTfNode, "enabled", "true"),
resource.TestCheckResourceAttr(caseEnforceTfNode, "enforce_consistent_case", "false"),
),
}, {
ResourceName: caseEnforceTfNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(caseEnforceTfNode),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func hclPolicyEnforceConsistentCaseResourceTemplate(projectName string, repoName string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "p" {
name = "%s"
description = "Test Project Description"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "r" {
project_id = azuredevops_project.p.id
name = "%s"
initialization {
init_type = "Clean"
}
}
`, projectName, repoName)
}

func hclRepoPolicyEnforceConsistentCaseBasic(projectName string, repoName string) string {
projectAndRepo := hclPolicyEnforceConsistentCaseResourceTemplate(projectName, repoName)
return fmt.Sprintf(`%s %s`, projectAndRepo, `
resource "azuredevops_repository_policy_case_enforcement" "p" {
project_id = azuredevops_project.p.id
enabled = true
blocking = true
enforce_consistent_case = true
repository_ids = [azuredevops_git_repository.r.id]
}
`)
}

func hclRepoPolicyEnforceConsistentCaseUpdate(projectName string, repoName string) string {
projectAndRepo := hclPolicyEnforceConsistentCaseResourceTemplate(projectName, repoName)
return fmt.Sprintf(`%s %s`, projectAndRepo, `
resource "azuredevops_repository_policy_case_enforcement" "p" {
project_id = azuredevops_project.p.id
enabled = true
blocking = true
enforce_consistent_case = false
repository_ids = [azuredevops_git_repository.r.id]
}
`)
}

func hclProjectPolicyEnforceConsistentCaseBasic(projectName string, repoName string) string {
projectAndRepo := hclPolicyEnforceConsistentCaseResourceTemplate(projectName, repoName)
return fmt.Sprintf(`%s %s`, projectAndRepo, `
resource "azuredevops_repository_policy_case_enforcement" "p" {
project_id = azuredevops_project.p.id
enabled = true
blocking = true
enforce_consistent_case = true
depends_on = [azuredevops_git_repository.r]
}
`)
}

func hclProjectPolicyEnforceConsistentCaseUpdate(projectName string, repoName string) string {
projectAndRepo := hclPolicyEnforceConsistentCaseResourceTemplate(projectName, repoName)
return fmt.Sprintf(`%s %s`, projectAndRepo, `
resource "azuredevops_repository_policy_case_enforcement" "p" {
project_id = azuredevops_project.p.id
enabled = true
blocking = true
enforce_consistent_case = false
depends_on = [azuredevops_git_repository.r]
}
`)
}
Loading

0 comments on commit 73a5975

Please sign in to comment.