Skip to content

Commit

Permalink
Adding Check Destroy to Instance Variable test and project share grou…
Browse files Browse the repository at this point in the history
…p test
  • Loading branch information
Shocktrooper committed Mar 31, 2022
1 parent 1fdf175 commit a29f12a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
25 changes: 24 additions & 1 deletion internal/provider/resource_gitlab_instance_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion internal/provider/resource_gitlab_project_share_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit a29f12a

Please sign in to comment.