Skip to content

Commit

Permalink
test: add more test cases for @ signs
Browse files Browse the repository at this point in the history
  • Loading branch information
georgijd-form3 committed Dec 5, 2023
1 parent 3219075 commit 273d913
Showing 1 changed file with 120 additions and 49 deletions.
169 changes: 120 additions & 49 deletions codeowners/resource_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,100 @@ const testAccFileConfigUpdate = `
]
}`

const testFileConfigLeadingAtSignOld = `
resource "codeowners_file" "test-add-at-sign" {
repository_name = "enforcement-test-repo"
repository_owner = "form3tech-oss"
rules = [
{
pattern = "*"
usernames = [ "expert" ]
},
{
pattern = "*.java"
usernames = [ "java-expert", "java-guru" ]
}
]
}
resource "codeowners_file" "test-remove-at-sign" {
repository_name = "enforcement-test-repo"
repository_owner = "form3tech-oss"
rules = [
{
pattern = "*"
usernames = [ "@expert" ]
},
{
pattern = "*.java"
usernames = [ "@java-expert", "@java-guru" ]
}
]
}
resource "codeowners_file" "test-toggle-at-sign" {
repository_name = "enforcement-test-repo"
repository_owner = "form3tech-oss"
rules = [
{
pattern = "*"
usernames = [ "expert" ]
},
{
pattern = "*.java"
usernames = [ "java-expert", "@java-guru" ]
}
]
}
`

const testFileConfigLeadingAtSignNew = `
resource "codeowners_file" "test-add-at-sign" {
repository_name = "enforcement-test-repo"
repository_owner = "form3tech-oss"
rules = [
{
pattern = "*"
usernames = [ "@expert" ]
},
{
pattern = "*.java"
usernames = [ "@java-expert", "@java-guru" ]
}
]
}
resource "codeowners_file" "test-remove-at-sign" {
repository_name = "enforcement-test-repo"
repository_owner = "form3tech-oss"
rules = [
{
pattern = "*"
usernames = [ "expert" ]
},
{
pattern = "*.java"
usernames = [ "java-expert", "java-guru" ]
}
]
}
resource "codeowners_file" "test-toggle-at-sign" {
repository_name = "enforcement-test-repo"
repository_owner = "form3tech-oss"
rules = [
{
pattern = "*"
usernames = [ "@expert" ]
},
{
pattern = "*.java"
usernames = [ "@java-expert", "java-guru" ]
}
]
}
`

func TestAccResourceFile_basic(t *testing.T) {
var before, after File

Expand Down Expand Up @@ -107,58 +201,35 @@ func TestAccResourceFile_basic(t *testing.T) {
})
}

const testAccFileConfigLeadingAtSign = `
resource "codeowners_file" "my-codeowners-file" {
repository_name = "enforcement-test-repo"
repository_owner = "form3tech-oss"
rules = [
{
pattern = "*"
usernames = [ "@expert" ]
},
{
pattern = "*.java"
usernames = [ "java-expert", "@java-guru" ]
}
]
}`

func TestAccResourceFile_OptionalAtSign(t *testing.T) {
resourceName := "codeowners_file.my-codeowners-file"
resourceNames := []string{
"codeowners_file.test-add-at-sign",
"codeowners_file.test-remove-at-sign",
"codeowners_file.test-toggle-at-sign",
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: resourceName,
Providers: testAccProviders,
CheckDestroy: testAccCheckFileDestroy,
Steps: []resource.TestStep{
{
Config: testAccFileConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "rules.#", "2"),
resource.TestCheckResourceAttr(resourceName, "rules.0.pattern", "*"),
resource.TestCheckResourceAttr(resourceName, "rules.0.usernames.#", "1"),
resource.TestCheckResourceAttr(resourceName, "rules.0.usernames.1327207234", "expert"),
resource.TestCheckResourceAttr(resourceName, "rules.1.pattern", "*.java"),
resource.TestCheckResourceAttr(resourceName, "rules.1.usernames.#", "2"),
resource.TestCheckResourceAttr(resourceName, "rules.1.usernames.2414450220", "java-guru"),
resource.TestCheckResourceAttr(resourceName, "rules.1.usernames.680681689", "java-expert"),
resource.TestCheckResourceAttr(resourceName, "repository_name", "enforcement-test-repo"),
resource.TestCheckResourceAttr(resourceName, "repository_owner", "form3tech-oss"),
resource.TestCheckResourceAttr(resourceName, "branch", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccFileConfigLeadingAtSign,
PlanOnly: true,
for _, resourceName := range resourceNames {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: resourceName,
Providers: testAccProviders,
CheckDestroy: testAccCheckFileDestroy,
Steps: []resource.TestStep{
{
Config: testFileConfigLeadingAtSignOld,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testFileConfigLeadingAtSignNew,
PlanOnly: true,
},
},
},
})
})
}
}

func testAccCheckFileDestroy(s *terraform.State) error {
Expand Down

0 comments on commit 273d913

Please sign in to comment.