-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(all): acc. test working against real infrastructure (#68)
* test(all): acc. test working against real infrastructure * test(all): acc. test working against real infrastructure #2 * test(all): acc. test working against real infrastructure #3
- Loading branch information
Showing
40 changed files
with
894 additions
and
1,246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package acctest | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/kiwicom/terraform-provider-montecarlo/internal" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/providerserver" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
) | ||
|
||
// testAccProtoV6ProviderFactories are used to instantiate a provider during | ||
// acceptance testing. The factory function will be invoked for every Terraform | ||
// CLI command executed to create a provider server to which the CLI can | ||
// reattach. | ||
var TestAccProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ | ||
"montecarlo": providerserver.NewProtocol6WithError(internal.New("test")()), | ||
} | ||
|
||
func TestAccPreCheck(t *testing.T) { | ||
if v := os.Getenv("MC_API_KEY_ID"); v == "" { | ||
t.Fatalf("'MC_API_KEY_ID' must be set for acceptance tests") | ||
} else if v := os.Getenv("MC_API_KEY_TOKEN"); v == "" { | ||
t.Fatalf("'MC_API_KEY_TOKEN' must be set for acceptance tests") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package authorization_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/kiwicom/terraform-provider-montecarlo/internal/acctest" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/config" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
func TestAccIamGroupResource(t *testing.T) { | ||
mc_api_key_id := os.Getenv("MC_API_KEY_ID") | ||
mc_api_key_token := os.Getenv("MC_API_KEY_TOKEN") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.TestAccPreCheck(t) }, | ||
Steps: []resource.TestStep{ | ||
{ // Create and Read testing | ||
ProtoV6ProviderFactories: acctest.TestAccProviderFactories, | ||
ConfigFile: config.TestNameFile("create.tf"), | ||
ConfigVariables: config.Variables{ | ||
"montecarlo_api_key_id": config.StringVariable(mc_api_key_id), | ||
"montecarlo_api_key_token": config.StringVariable(mc_api_key_token), | ||
}, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "name", "group-1"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "label", "group-1"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "description", ""), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "role", "mcd/editor"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "domains.#", "0"), | ||
resource.TestCheckNoResourceAttr("montecarlo_iam_group.test", "ssoGroup"), | ||
), | ||
}, | ||
{ // ImportState testing | ||
ProtoV6ProviderFactories: acctest.TestAccProviderFactories, | ||
ConfigVariables: config.Variables{ | ||
"montecarlo_api_key_id": config.StringVariable(mc_api_key_id), | ||
"montecarlo_api_key_token": config.StringVariable(mc_api_key_token), | ||
}, | ||
ResourceName: "montecarlo_iam_group.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateIdFunc: func(s *terraform.State) (string, error) { | ||
return s.RootModule().Resources["montecarlo_iam_group.test"].Primary.Attributes["name"], nil | ||
}, | ||
ImportStateVerifyIdentifierAttribute: "name", | ||
}, | ||
{ // Update and Read testing | ||
ProtoV6ProviderFactories: acctest.TestAccProviderFactories, | ||
ConfigFile: config.TestNameFile("update.tf"), | ||
ConfigVariables: config.Variables{ | ||
"montecarlo_api_key_id": config.StringVariable(mc_api_key_id), | ||
"montecarlo_api_key_token": config.StringVariable(mc_api_key_token), | ||
}, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "name", "group-1"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "label", "group-1"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "description", ""), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "role", "mcd/viewer"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "domains.#", "2"), | ||
resource.TestCheckTypeSetElemAttr("montecarlo_iam_group.test", "domains.*", "ba0c4080-089d-4377-8878-466c31d19807"), | ||
resource.TestCheckTypeSetElemAttr("montecarlo_iam_group.test", "domains.*", "dd4cda19-1c5c-4339-9628-76376c9e281e"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_group.test", "sso_group", "ssoGroup1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package authorization_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/kiwicom/terraform-provider-montecarlo/internal/acctest" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/config" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccIamMemberResource(t *testing.T) { | ||
mc_api_key_id := os.Getenv("MC_API_KEY_ID") | ||
mc_api_key_token := os.Getenv("MC_API_KEY_TOKEN") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.TestAccPreCheck(t) }, | ||
Steps: []resource.TestStep{ | ||
{ // Create and Read testing | ||
ProtoV6ProviderFactories: acctest.TestAccProviderFactories, | ||
ConfigFile: config.TestNameFile("create.tf"), | ||
ConfigVariables: config.Variables{ | ||
"montecarlo_api_key_id": config.StringVariable(mc_api_key_id), | ||
"montecarlo_api_key_token": config.StringVariable(mc_api_key_token), | ||
}, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("montecarlo_iam_member.test", "group", "groups/TestAccIamMemberResource"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_member.test", "member", "user:[email protected]"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_member.test", "member_id", "21ddb883-7586-4034-9767-e5f966ec10df"), | ||
), | ||
}, | ||
{ // ImportState testing | ||
ProtoV6ProviderFactories: acctest.TestAccProviderFactories, | ||
ConfigVariables: config.Variables{ | ||
"montecarlo_api_key_id": config.StringVariable(mc_api_key_id), | ||
"montecarlo_api_key_token": config.StringVariable(mc_api_key_token), | ||
}, | ||
ResourceName: "montecarlo_iam_member.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateId: "groups/TestAccIamMemberResource,user:[email protected]", | ||
ImportStateVerifyIdentifierAttribute: "group", | ||
}, | ||
{ // Update and Read testing | ||
ProtoV6ProviderFactories: acctest.TestAccProviderFactories, | ||
ConfigFile: config.TestNameFile("update_group.tf"), | ||
ConfigVariables: config.Variables{ | ||
"montecarlo_api_key_id": config.StringVariable(mc_api_key_id), | ||
"montecarlo_api_key_token": config.StringVariable(mc_api_key_token), | ||
}, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("montecarlo_iam_member.test", "group", "groups/TestAccIamMemberResource2"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_member.test", "member", "user:[email protected]"), | ||
resource.TestCheckResourceAttr("montecarlo_iam_member.test", "member_id", "21ddb883-7586-4034-9767-e5f966ec10df"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
19 changes: 19 additions & 0 deletions
19
internal/authorization/testdata/TestAccIamGroupResource/create.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "montecarlo_api_key_id" { | ||
type = string | ||
} | ||
|
||
variable "montecarlo_api_key_token" { | ||
type = string | ||
} | ||
|
||
provider "montecarlo" { | ||
account_service_key = { | ||
id = var.montecarlo_api_key_id # (secret) | ||
token = var.montecarlo_api_key_token # (secret) | ||
} | ||
} | ||
|
||
resource "montecarlo_iam_group" "test" { | ||
name = "group-1" | ||
role = "mcd/editor" | ||
} |
24 changes: 24 additions & 0 deletions
24
internal/authorization/testdata/TestAccIamGroupResource/update.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
variable "montecarlo_api_key_id" { | ||
type = string | ||
} | ||
|
||
variable "montecarlo_api_key_token" { | ||
type = string | ||
} | ||
|
||
provider "montecarlo" { | ||
account_service_key = { | ||
id = var.montecarlo_api_key_id # (secret) | ||
token = var.montecarlo_api_key_token # (secret) | ||
} | ||
} | ||
|
||
resource "montecarlo_iam_group" "test" { | ||
name = "group-1" | ||
role = "mcd/viewer" | ||
sso_group = "ssoGroup1" | ||
domains = [ | ||
"ba0c4080-089d-4377-8878-466c31d19807", | ||
"dd4cda19-1c5c-4339-9628-76376c9e281e" | ||
] | ||
} |
Oops, something went wrong.