From 273d9137571fb39386a79d83971a9242359eaac4 Mon Sep 17 00:00:00 2001 From: Georgi Dimitrov Date: Tue, 5 Dec 2023 16:04:25 +0000 Subject: [PATCH] test: add more test cases for @ signs --- codeowners/resource_file_test.go | 169 ++++++++++++++++++++++--------- 1 file changed, 120 insertions(+), 49 deletions(-) diff --git a/codeowners/resource_file_test.go b/codeowners/resource_file_test.go index 0a80e69b..c7f558d4 100644 --- a/codeowners/resource_file_test.go +++ b/codeowners/resource_file_test.go @@ -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 @@ -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 {