Skip to content

Commit

Permalink
feat: added test cases for gitlab
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Theuermann <[email protected]>
  • Loading branch information
mati007thm committed Dec 6, 2024
1 parent 8272dc9 commit 25276a1
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions internal/provider/integration_gitlab_resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package provider

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccGitLabResource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccGitLabResourceConfig(accSpace.ID(), "one", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "name", "one"),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "space_id", accSpace.ID()),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "discovery.0.groups", "true"),
),
},
{
Config: testAccGitLabResourceWithSpaceInProviderConfig(accSpace.ID(), "two", "abctoken12345"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "name", "two"),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "space_id", accSpace.ID()),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "credentials.0.token", "abctoken12345"),
),
},
// ImportState testing
// @afiune this doesn't work since most of our resources doesn't have the `id` attribute
// if we add it, instead of the `mrn` or as a copy, this import test will work
// {
// ResourceName: "mondoo_integration_gitlab.test",
// ImportState: true,
// ImportStateVerify: true,
// },
// Update and Read testing
{
Config: testAccGitLabResourceConfig(accSpace.ID(), "one", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "name", "one"),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "space_id", accSpace.ID()),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "discovery.0.groups", "true"),
),
},
{
Config: testAccGitLabResourceWithSpaceInProviderConfig(accSpace.ID(), "two", "abctoken12345"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "name", "two"),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "space_id", accSpace.ID()),
resource.TestCheckResourceAttr("mondoo_integration_gitlab.test", "credentials.0.token", "abctoken12345"),
),
},
// Delete testing automatically occurs in TestCase
},
})
}

func testAccGitLabResourceConfig(spaceID, intName string, discoveryGroup bool) string {
return fmt.Sprintf(`
resource "mondoo_integration_gitlab" "test" {
space_id = %[1]q
name = %[2]q
base_url = "https://my-self-hosted-gitlab.com"
group = "my-group"
discovery = {
groups = %[3]t
projects = true
terraform = true
k8s_manifests = true
}
credentials = {
token = "abcd1234567890"
}
}
`, spaceID, intName, discoveryGroup)
}

func testAccGitLabResourceWithSpaceInProviderConfig(spaceID, intName, token string) string {
return fmt.Sprintf(`
provider "mondoo" {
space = %[1]q
}
resource "mondoo_integration_gitlab" "test" {
name = %[2]q
base_url = "https://my-self-hosted-gitlab.com"
group = "my-group"
discovery = {
groups = true
projects = true
terraform = true
k8s_manifests = true
}
credentials = {
token = %[3]q
}
}
`, spaceID, intName, token)
}

0 comments on commit 25276a1

Please sign in to comment.