From 60d19c47a441ff30fd810dbc12c1dd2ff773c6a3 Mon Sep 17 00:00:00 2001 From: Shocktrooper Date: Wed, 30 Mar 2022 19:42:45 -0500 Subject: [PATCH 1/3] Linter fixes + small refactors --- GNUmakefile | 2 +- internal/provider/resource_gitlab_group.go | 5 +- .../resource_gitlab_group_share_group.go | 5 +- .../resource_gitlab_group_share_group_test.go | 140 ++++++++---------- .../provider/resource_gitlab_group_test.go | 5 +- .../resource_gitlab_instance_variable.go | 5 +- .../resource_gitlab_instance_variable_test.go | 25 +++- .../resource_gitlab_project_freeze_period.go | 5 +- .../resource_gitlab_project_membership.go | 5 +- ...esource_gitlab_project_share_group_test.go | 30 +++- .../provider/resource_gitlab_project_test.go | 25 +--- .../provider/resource_gitlab_service_jira.go | 5 +- ...resource_gitlab_service_microsoft_teams.go | 5 +- 13 files changed, 139 insertions(+), 123 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 38d7948e1..0ab04394b 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -20,7 +20,7 @@ endif test: ## Run unit tests. go test $(TESTARGS) $(PROVIDER_SRC_DIR) -TFPROVIDERLINTX_CHECKS = -XAT001=false -XR003=false -XS002=false +TFPROVIDERLINTX_CHECKS = -XR003=false -XS002=false fmt: tool-golangci-lint tool-tfproviderlintx tool-terraform tool-shfmt ## Format files and fix issues. gofmt -w -s . diff --git a/internal/provider/resource_gitlab_group.go b/internal/provider/resource_gitlab_group.go index 71b827b98..4b43fcad9 100644 --- a/internal/provider/resource_gitlab_group.go +++ b/internal/provider/resource_gitlab_group.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "strings" "time" @@ -251,9 +250,9 @@ func resourceGitlabGroupRead(ctx context.Context, d *schema.ResourceData, meta i client := meta.(*gitlab.Client) log.Printf("[DEBUG] read gitlab group %s", d.Id()) - group, resp, err := client.Groups.GetGroup(d.Id(), nil, gitlab.WithContext(ctx)) + group, _, err := client.Groups.GetGroup(d.Id(), nil, gitlab.WithContext(ctx)) if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if is404(err) { log.Printf("[DEBUG] gitlab group %s not found so removing from state", d.Id()) d.SetId("") return nil diff --git a/internal/provider/resource_gitlab_group_share_group.go b/internal/provider/resource_gitlab_group_share_group.go index 01a142365..2672cce37 100644 --- a/internal/provider/resource_gitlab_group_share_group.go +++ b/internal/provider/resource_gitlab_group_share_group.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -93,9 +92,9 @@ func resourceGitlabGroupShareGroupRead(ctx context.Context, d *schema.ResourceDa } // Query main group - group, resp, err := client.Groups.GetGroup(groupId, nil, gitlab.WithContext(ctx)) + group, _, err := client.Groups.GetGroup(groupId, nil, gitlab.WithContext(ctx)) if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if is404(err) { log.Printf("[DEBUG] gitlab group %s not found so removing from state", groupId) d.SetId("") return nil diff --git a/internal/provider/resource_gitlab_group_share_group_test.go b/internal/provider/resource_gitlab_group_share_group_test.go index 8b932f014..af19bf9d6 100644 --- a/internal/provider/resource_gitlab_group_share_group_test.go +++ b/internal/provider/resource_gitlab_group_share_group_test.go @@ -4,64 +4,42 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/xanzy/go-gitlab" ) func TestAccGitlabGroupShareGroup_basic(t *testing.T) { - randName := acctest.RandomWithPrefix("acctest") + testAccCheck(t) + + mainGroup := testAccCreateGroups(t, 1)[0] + sharedGroup := testAccCreateGroups(t, 1)[0] - // lintignore: AT001 // TODO: Resolve this tfproviderlint issue resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: providerFactories, + CheckDestroy: testAccCheckGitlabShareGroupDestroy, Steps: []resource.TestStep{ // Share a new group with another group { - Config: testAccGitlabGroupShareGroupConfig( - randName, + Config: testAccGitlabGroupShareGroupConfig(mainGroup.ID, sharedGroup.ID, ` group_access = "guest" expires_at = "2099-01-01" `, ), - Check: testAccCheckGitlabGroupSharedWithGroup(randName, "2099-01-01", gitlab.GuestPermissions), + Check: testAccCheckGitlabGroupSharedWithGroup(mainGroup.Name, sharedGroup.Name, "2099-01-01", gitlab.GuestPermissions), }, - // Update the share group - { - Config: testAccGitlabGroupShareGroupConfig(randName, `group_access = "reporter"`), - Check: testAccCheckGitlabGroupSharedWithGroup(randName, "", gitlab.ReporterPermissions), - }, - // Delete the gitlab_group_share_group resource { - Config: testAccGitlabGroupShareGroupConfigDelete(randName), - Check: testAccCheckGitlabGroupIsNotShared(randName), + // Verify Import + ResourceName: "gitlab_group_share_group.test", + ImportState: true, + ImportStateVerify: true, }, - }, - }) -} - -// lintignore: AT002 // TODO: Resolve this tfproviderlint issue -func TestAccGitlabGroupShareGroup_import(t *testing.T) { - randName := acctest.RandomWithPrefix("acctest") - - resource.Test(t, resource.TestCase{ - ProviderFactories: providerFactories, - PreCheck: func() { testAccPreCheck(t) }, - CheckDestroy: testAccCheckGitlabGroupDestroy, - Steps: []resource.TestStep{ + // Update the share group { - // create shared groups - Config: testAccGitlabGroupShareGroupConfig( - randName, - ` - group_access = "guest" - expires_at = "2099-03-03" - `, - ), - Check: testAccCheckGitlabGroupSharedWithGroup(randName, "2099-03-03", gitlab.GuestPermissions), + Config: testAccGitlabGroupShareGroupConfig(mainGroup.ID, sharedGroup.ID, `group_access = "reporter"`), + Check: testAccCheckGitlabGroupSharedWithGroup(mainGroup.Name, sharedGroup.Name, "", gitlab.ReporterPermissions), }, { // Verify Import @@ -69,17 +47,18 @@ func TestAccGitlabGroupShareGroup_import(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + // Delete the gitlab_group_share_group resource + { + Config: testAccGitlabGroupShareGroupConfigDelete(), + Check: testAccCheckGitlabGroupIsNotShared(mainGroup.Name), + }, }, }) } -func testAccCheckGitlabGroupSharedWithGroup( - groupName string, - expireTime string, - accessLevel gitlab.AccessLevelValue, -) resource.TestCheckFunc { +func testAccCheckGitlabGroupSharedWithGroup(mainGroupName string, sharedGroupName string, expireTime string, accessLevel gitlab.AccessLevelValue) resource.TestCheckFunc { return func(_ *terraform.State) error { - mainGroup, _, err := testGitlabClient.Groups.GetGroup(fmt.Sprintf("%s_main", groupName), nil) + mainGroup, _, err := testGitlabClient.Groups.GetGroup(mainGroupName, nil) if err != nil { return err } @@ -91,8 +70,8 @@ func testAccCheckGitlabGroupSharedWithGroup( sharedGroup := mainGroup.SharedWithGroups[0] - if sharedGroup.GroupName != fmt.Sprintf("%s_share", groupName) { - return fmt.Errorf("group name was %s (wanted %s)", sharedGroup.GroupName, fmt.Sprintf("%s_share", groupName)) + if sharedGroup.GroupName != sharedGroupName { + return fmt.Errorf("group name was %s (wanted %s)", sharedGroup.GroupName, sharedGroupName) } if gitlab.AccessLevelValue(sharedGroup.GroupAccessLevel) != accessLevel { @@ -109,9 +88,9 @@ func testAccCheckGitlabGroupSharedWithGroup( } } -func testAccCheckGitlabGroupIsNotShared(groupName string) resource.TestCheckFunc { +func testAccCheckGitlabGroupIsNotShared(mainGroupName string) resource.TestCheckFunc { return func(_ *terraform.State) error { - mainGroup, _, err := testGitlabClient.Groups.GetGroup(fmt.Sprintf("%s_main", groupName), nil) + mainGroup, _, err := testGitlabClient.Groups.GetGroup(mainGroupName, nil) if err != nil { return err } @@ -125,46 +104,51 @@ func testAccCheckGitlabGroupIsNotShared(groupName string) resource.TestCheckFunc } } -func testAccGitlabGroupShareGroupConfig( - randName string, - shareGroupSettings string, -) string { - return fmt.Sprintf( - ` - resource "gitlab_group" "test_main" { - name = "%[1]s_main" - path = "%[1]s_main" +func testAccCheckGitlabShareGroupDestroy(s *terraform.State) error { + var groupId string + var sharedGroupId int + var err error + + for _, rs := range s.RootModule().Resources { + if rs.Type == "gitlab_group_share_group" { + groupId, sharedGroupId, err = groupIdsFromId(rs.Primary.ID) + if err != nil { + return fmt.Errorf("[ERROR] cannot get Group ID and ShareGroupId from input: %v", rs.Primary.ID) + } + + // Get Main Group + group, _, err := testGitlabClient.Groups.GetGroup(groupId, nil) + if err != nil { + return err + } + + // Make sure that SharedWithGroups attribute on the main group does not contain the shared group id at all + for _, sharedGroup := range group.SharedWithGroups { + if sharedGroupId == sharedGroup.GroupID { + return fmt.Errorf("GitLab Group Share %d still exists", sharedGroupId) + } + } } + } - resource "gitlab_group" "test_share" { - name = "%[1]s_share" - path = "%[1]s_share" - } + return nil +} +func testAccGitlabGroupShareGroupConfig(mainGroupId int, shareGroupId int, shareGroupSettings string) string { + return fmt.Sprintf( + ` resource "gitlab_group_share_group" "test" { - group_id = gitlab_group.test_main.id - share_group_id = gitlab_group.test_share.id - %[2]s + group_id = %[1]d + share_group_id = %[2]d + %[3]s } `, - randName, + mainGroupId, + shareGroupId, shareGroupSettings, ) } -func testAccGitlabGroupShareGroupConfigDelete(randName string) string { - return fmt.Sprintf( - ` - resource "gitlab_group" "test_main" { - name = "%[1]s_main" - path = "%[1]s_main" - } - - resource "gitlab_group" "test_share" { - name = "%[1]s_share" - path = "%[1]s_share" - } - `, - randName, - ) +func testAccGitlabGroupShareGroupConfigDelete() string { + return `` } diff --git a/internal/provider/resource_gitlab_group_test.go b/internal/provider/resource_gitlab_group_test.go index 04d610ada..822de1f42 100644 --- a/internal/provider/resource_gitlab_group_test.go +++ b/internal/provider/resource_gitlab_group_test.go @@ -2,7 +2,6 @@ package provider import ( "fmt" - "net/http" "testing" "time" @@ -284,8 +283,8 @@ func testAccCheckGitlabGroupDisappears(group *gitlab.Group) resource.TestCheckFu // Fixes groups API async deletion issue // https://github.com/gitlabhq/terraform-provider-gitlab/issues/319 for start := time.Now(); time.Since(start) < 15*time.Second; { - g, resp, err := testGitlabClient.Groups.GetGroup(group.ID, nil) - if resp != nil && resp.StatusCode == http.StatusNotFound { + g, _, err := testGitlabClient.Groups.GetGroup(group.ID, nil) + if is404(err) { return nil } if g != nil && g.MarkedForDeletionOn != nil { diff --git a/internal/provider/resource_gitlab_instance_variable.go b/internal/provider/resource_gitlab_instance_variable.go index c834b0ac8..e9aaaca65 100644 --- a/internal/provider/resource_gitlab_instance_variable.go +++ b/internal/provider/resource_gitlab_instance_variable.go @@ -3,7 +3,6 @@ package provider import ( "context" "log" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -96,9 +95,9 @@ func resourceGitlabInstanceVariableRead(ctx context.Context, d *schema.ResourceD log.Printf("[DEBUG] read gitlab instance level CI variable %s", key) - v, resp, err := client.InstanceVariables.GetVariable(key, gitlab.WithContext(ctx)) + v, _, err := client.InstanceVariables.GetVariable(key, gitlab.WithContext(ctx)) if err != nil { - if resp.StatusCode == http.StatusNotFound { + if is404(err) { log.Printf("[DEBUG] gitlab instance level CI variable for %s not found so removing from state", d.Id()) d.SetId("") return nil diff --git a/internal/provider/resource_gitlab_instance_variable_test.go b/internal/provider/resource_gitlab_instance_variable_test.go index 1ee6be491..f3db99d33 100644 --- a/internal/provider/resource_gitlab_instance_variable_test.go +++ b/internal/provider/resource_gitlab_instance_variable_test.go @@ -15,10 +15,10 @@ func TestAccGitlabInstanceVariable_basic(t *testing.T) { var instanceVariable gitlab.InstanceVariable rString := acctest.RandString(5) - // lintignore: AT001 // TODO: Resolve this tfproviderlint issue resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: providerFactories, + CheckDestroy: testAccCheckGitlabInstanceVariableDestroy, Steps: []resource.TestStep{ // Create a variable with default options { @@ -120,6 +120,29 @@ func testAccCheckGitlabInstanceVariableExists(n string, instanceVariable *gitlab } } +func testAccCheckGitlabInstanceVariableDestroy(s *terraform.State) error { + var key string + + for _, rs := range s.RootModule().Resources { + if rs.Type == "gitlab_instance_variable" { + key = rs.Primary.ID + } + } + + iv, _, err := testGitlabClient.InstanceVariables.GetVariable(key) + if err == nil { + if iv != nil { + return fmt.Errorf("Instance Variable %s still exists", key) + } + } else { + if !is404(err) { + return err + } + } + + return nil +} + type testAccGitlabInstanceVariableExpectedAttributes struct { Key string Value string diff --git a/internal/provider/resource_gitlab_project_freeze_period.go b/internal/provider/resource_gitlab_project_freeze_period.go index b2db55ef6..7af5a1ebd 100644 --- a/internal/provider/resource_gitlab_project_freeze_period.go +++ b/internal/provider/resource_gitlab_project_freeze_period.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -84,9 +83,9 @@ func resourceGitlabProjectFreezePeriodRead(ctx context.Context, d *schema.Resour log.Printf("[DEBUG] read gitlab FreezePeriod %s/%d", projectID, freezePeriodID) - freezePeriod, resp, err := client.FreezePeriods.GetFreezePeriod(projectID, freezePeriodID, gitlab.WithContext(ctx)) + freezePeriod, _, err := client.FreezePeriods.GetFreezePeriod(projectID, freezePeriodID, gitlab.WithContext(ctx)) if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if is404(err) { log.Printf("[DEBUG] project freeze period for %s not found so removing it from state", d.Id()) d.SetId("") return nil diff --git a/internal/provider/resource_gitlab_project_membership.go b/internal/provider/resource_gitlab_project_membership.go index 93daa52b5..ee0c1d09f 100644 --- a/internal/provider/resource_gitlab_project_membership.go +++ b/internal/provider/resource_gitlab_project_membership.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "strconv" "strings" @@ -85,9 +84,9 @@ func resourceGitlabProjectMembershipRead(ctx context.Context, d *schema.Resource return diag.FromErr(err) } - projectMember, resp, err := client.ProjectMembers.GetProjectMember(projectId, userId, gitlab.WithContext(ctx)) + projectMember, _, err := client.ProjectMembers.GetProjectMember(projectId, userId, gitlab.WithContext(ctx)) if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if is404(err) { log.Printf("[DEBUG] gitlab project membership for %s not found so removing from state", d.Id()) d.SetId("") return nil diff --git a/internal/provider/resource_gitlab_project_share_group_test.go b/internal/provider/resource_gitlab_project_share_group_test.go index 7a1506e91..72760282c 100644 --- a/internal/provider/resource_gitlab_project_share_group_test.go +++ b/internal/provider/resource_gitlab_project_share_group_test.go @@ -45,10 +45,10 @@ func TestResourceGitlabProjectShareGroupStateUpgradeV0(t *testing.T) { func TestAccGitlabProjectShareGroup_basic(t *testing.T) { randName := acctest.RandomWithPrefix("acctest") - // lintignore: AT001 // TODO: Resolve this tfproviderlint issue resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: providerFactories, + CheckDestroy: testAccCheckGitlabProjectShareGroupDestroy, Steps: []resource.TestStep{ // Share a new project with a new group. { @@ -109,6 +109,34 @@ func testAccCheckGitlabProjectIsNotShared(projectName string) resource.TestCheck } } +func testAccCheckGitlabProjectShareGroupDestroy(s *terraform.State) error { + var projectId string + var groupId int + var err error + + for _, rs := range s.RootModule().Resources { + if rs.Type == "gitlab_project_share_group" { + projectId, groupId, err = projectIdAndGroupIdFromId(rs.Primary.ID) + if err != nil { + return fmt.Errorf("[ERROR] cannot get project ID and group ID from input: %v", rs.Primary.ID) + } + + proj, _, err := testGitlabClient.Projects.GetProject(projectId, nil) + if err != nil { + return err + } + + for _, v := range proj.SharedWithGroups { + if groupId == v.GroupID { + return fmt.Errorf("GitLab Project Share %d still exists", groupId) + } + } + } + } + + return nil +} + func testAccGitlabProjectShareGroupConfig(randName, accessLevel string) string { return fmt.Sprintf(` resource "gitlab_project" "test" { diff --git a/internal/provider/resource_gitlab_project_test.go b/internal/provider/resource_gitlab_project_test.go index 4b89c73f6..c834a8a9f 100644 --- a/internal/provider/resource_gitlab_project_test.go +++ b/internal/provider/resource_gitlab_project_test.go @@ -1,5 +1,3 @@ -// lintignore: AT012 // TODO: Resolve this tfproviderlint issue - package provider import ( @@ -665,8 +663,7 @@ func TestAccGitlabProject_willErrorOnAPIFailure(t *testing.T) { }) } -// lintignore: AT002 // TODO: Resolve this tfproviderlint issue -func TestAccGitlabProject_import(t *testing.T) { +func TestAccGitlabProject_imprt(t *testing.T) { rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -690,7 +687,7 @@ func TestAccGitlabProject_import(t *testing.T) { }) } -func TestAccGitlabProject_nestedImport(t *testing.T) { +func TestAccGitlabProject_nestedImprt(t *testing.T) { rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -770,12 +767,8 @@ func TestAccGitlabProject_transfer(t *testing.T) { }) } -// lintignore: AT002 // not a Terraform import test -func TestAccGitlabProject_importURL(t *testing.T) { - // Since we do some manual setup in this test, we need to handle the test skip first. - if os.Getenv(resource.EnvTfAcc) == "" { - t.Skip(fmt.Sprintf("Acceptance tests skipped unless env '%s' set", resource.EnvTfAcc)) - } +func TestAccGitlabProject_imprtURL(t *testing.T) { + testAccCheck(t) rInt := acctest.RandInt() @@ -898,12 +891,8 @@ func testAccCheckGitlabProjectMirroredAttributes(project *gitlab.Project, want * } } -// lintignore: AT002 // not a Terraform import test -func TestAccGitlabProject_importURLMirrored(t *testing.T) { - // Since we do some manual setup in this test, we need to handle the test skip first. - if os.Getenv(resource.EnvTfAcc) == "" { - t.Skip(fmt.Sprintf("Acceptance tests skipped unless env '%s' set", resource.EnvTfAcc)) - } +func TestAccGitlabProject_ImprtURLMirrored(t *testing.T) { + testAccCheck(t) var mirror gitlab.Project rInt := acctest.RandInt() @@ -1021,10 +1010,10 @@ func TestAccGitlabProject_importURLMirrored(t *testing.T) { func TestAccGitlabProject_templateMutualExclusiveNameAndID(t *testing.T) { rInt := acctest.RandInt() - // lintignore: AT001 // TODO: Resolve this tfproviderlint issue resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: providerFactories, + CheckDestroy: testAccCheckGitlabProjectDestroy, Steps: []resource.TestStep{ { Config: testAccCheckMutualExclusiveNameAndID(rInt), diff --git a/internal/provider/resource_gitlab_service_jira.go b/internal/provider/resource_gitlab_service_jira.go index dd104f78e..6c838e49a 100644 --- a/internal/provider/resource_gitlab_service_jira.go +++ b/internal/provider/resource_gitlab_service_jira.go @@ -3,7 +3,6 @@ package provider import ( "context" "log" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -169,9 +168,9 @@ func resourceGitlabServiceJiraRead(ctx context.Context, d *schema.ResourceData, client := meta.(*gitlab.Client) project := d.Get("project").(string) - p, resp, err := client.Projects.GetProject(project, nil, gitlab.WithContext(ctx)) + p, _, err := client.Projects.GetProject(project, nil, gitlab.WithContext(ctx)) if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if is404(err) { log.Printf("[DEBUG] Removing Gitlab Jira service %s because project %s not found", d.Id(), p.Name) d.SetId("") return nil diff --git a/internal/provider/resource_gitlab_service_microsoft_teams.go b/internal/provider/resource_gitlab_service_microsoft_teams.go index ccfbfcc98..5e0e5aa49 100644 --- a/internal/provider/resource_gitlab_service_microsoft_teams.go +++ b/internal/provider/resource_gitlab_service_microsoft_teams.go @@ -3,7 +3,6 @@ package provider import ( "context" "log" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -144,9 +143,9 @@ func resourceGitlabServiceMicrosoftTeamsRead(ctx context.Context, d *schema.Reso client := meta.(*gitlab.Client) project := d.Id() - p, resp, err := client.Projects.GetProject(project, nil, gitlab.WithContext(ctx)) + p, _, err := client.Projects.GetProject(project, nil, gitlab.WithContext(ctx)) if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if is404(err) { log.Printf("[DEBUG] Removing Gitlab Microsoft Teams service %s because project %s not found", d.Id(), p.Name) d.SetId("") return nil From f951203cfb155078dda2a5172a43ec14ab32dd1f Mon Sep 17 00:00:00 2001 From: Shocktrooper Date: Thu, 31 Mar 2022 12:14:16 -0500 Subject: [PATCH 2/3] Reverting lint ignore flag for XAT001 --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index 0ab04394b..38d7948e1 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -20,7 +20,7 @@ endif test: ## Run unit tests. go test $(TESTARGS) $(PROVIDER_SRC_DIR) -TFPROVIDERLINTX_CHECKS = -XR003=false -XS002=false +TFPROVIDERLINTX_CHECKS = -XAT001=false -XR003=false -XS002=false fmt: tool-golangci-lint tool-tfproviderlintx tool-terraform tool-shfmt ## Format files and fix issues. gofmt -w -s . From f3e1194dbae7cbba3984af87dd973a13e014740b Mon Sep 17 00:00:00 2001 From: Shocktrooper Date: Sun, 3 Apr 2022 21:14:14 +0000 Subject: [PATCH 3/3] Reverted and refactored some acceptance tests --- .../resource_gitlab_group_share_group_test.go | 37 +++++++------------ .../provider/resource_gitlab_project_test.go | 12 ++++-- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/internal/provider/resource_gitlab_group_share_group_test.go b/internal/provider/resource_gitlab_group_share_group_test.go index af19bf9d6..e07ac57de 100644 --- a/internal/provider/resource_gitlab_group_share_group_test.go +++ b/internal/provider/resource_gitlab_group_share_group_test.go @@ -47,10 +47,21 @@ func TestAccGitlabGroupShareGroup_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - // Delete the gitlab_group_share_group resource + // Update share group back to initial settings { - Config: testAccGitlabGroupShareGroupConfigDelete(), - Check: testAccCheckGitlabGroupIsNotShared(mainGroup.Name), + Config: testAccGitlabGroupShareGroupConfig(mainGroup.ID, sharedGroup.ID, + ` + group_access = "guest" + expires_at = "2099-01-01" + `, + ), + Check: testAccCheckGitlabGroupSharedWithGroup(mainGroup.Name, sharedGroup.Name, "2099-01-01", gitlab.GuestPermissions), + }, + { + // Verify Import + ResourceName: "gitlab_group_share_group.test", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -88,22 +99,6 @@ func testAccCheckGitlabGroupSharedWithGroup(mainGroupName string, sharedGroupNam } } -func testAccCheckGitlabGroupIsNotShared(mainGroupName string) resource.TestCheckFunc { - return func(_ *terraform.State) error { - mainGroup, _, err := testGitlabClient.Groups.GetGroup(mainGroupName, nil) - if err != nil { - return err - } - - sharedGroupsCount := len(mainGroup.SharedWithGroups) - if sharedGroupsCount != 0 { - return fmt.Errorf("Number of shared groups was %d (wanted %d)", sharedGroupsCount, 0) - } - - return nil - } -} - func testAccCheckGitlabShareGroupDestroy(s *terraform.State) error { var groupId string var sharedGroupId int @@ -148,7 +143,3 @@ func testAccGitlabGroupShareGroupConfig(mainGroupId int, shareGroupId int, share shareGroupSettings, ) } - -func testAccGitlabGroupShareGroupConfigDelete() string { - return `` -} diff --git a/internal/provider/resource_gitlab_project_test.go b/internal/provider/resource_gitlab_project_test.go index 04a4021ee..f93066b92 100644 --- a/internal/provider/resource_gitlab_project_test.go +++ b/internal/provider/resource_gitlab_project_test.go @@ -662,7 +662,8 @@ func TestAccGitlabProject_willErrorOnAPIFailure(t *testing.T) { }) } -func TestAccGitlabProject_imprt(t *testing.T) { +// lintignore: AT002 // specialized import test +func TestAccGitlabProject_import(t *testing.T) { rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -686,7 +687,8 @@ func TestAccGitlabProject_imprt(t *testing.T) { }) } -func TestAccGitlabProject_nestedImprt(t *testing.T) { +// lintignore: AT002 // specialized import test +func TestAccGitlabProject_nestedImport(t *testing.T) { rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -766,7 +768,8 @@ func TestAccGitlabProject_transfer(t *testing.T) { }) } -func TestAccGitlabProject_imprtURL(t *testing.T) { +// lintignore: AT002 // not a Terraform import test +func TestAccGitlabProject_importURL(t *testing.T) { testAccCheck(t) rInt := acctest.RandInt() @@ -890,7 +893,8 @@ func testAccCheckGitlabProjectMirroredAttributes(project *gitlab.Project, want * } } -func TestAccGitlabProject_ImprtURLMirrored(t *testing.T) { +// lintignore: AT002 // not a Terraform import test +func TestAccGitlabProject_ImportURLMirrored(t *testing.T) { testAccCheck(t) var mirror gitlab.Project