Skip to content

Commit

Permalink
Refactor project_from_id acc test to use non-networking resources (…
Browse files Browse the repository at this point in the history
…#10165) (#7079)

[upstream:194527b84f9fa2d12d51d821ae7a5b2b0f894be5]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Mar 12, 2024
1 parent 61e14bc commit 1100d9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .changelog/10165.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
39 changes: 17 additions & 22 deletions google-beta/functions/project_from_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccProviderFunction_project_from_id(t *testing.T) {
context := map[string]interface{}{
"function_name": "project_from_id",
"output_name": "project_id",
"resource_name": fmt.Sprintf("tf-test-project-id-func-%s", acctest.RandString(t, 10)),
"resource_name": fmt.Sprintf("tf_test_project_id_func_%s", acctest.RandString(t, 10)),
}

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -39,7 +39,7 @@ func TestAccProviderFunction_project_from_id(t *testing.T) {
},
{
// Can get the project from a resource's self_link in one step
// Uses google_compute_subnetwork resource's self_link attribute
// Uses google_bigquery_dataset resource's self_link attribute
Config: testProviderFunction_get_project_from_resource_self_link(context),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchOutput(context["output_name"].(string), projectIdRegex),
Expand All @@ -53,19 +53,19 @@ func testProviderFunction_get_project_from_resource_id(context map[string]interf
return acctest.Nprintf(`
# terraform block required for provider function to be found
terraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
required_providers {
google = {
source = "hashicorp/google"
}
}
}
resource "google_pubsub_topic" "default" {
name = "%{resource_name}"
}
output "%{output_name}" {
value = provider::google::%{function_name}(google_pubsub_topic.default.id)
value = provider::google::%{function_name}(google_pubsub_topic.default.id)
}
`, context)
}
Expand All @@ -74,25 +74,20 @@ func testProviderFunction_get_project_from_resource_self_link(context map[string
return acctest.Nprintf(`
# terraform block required for provider function to be found
terraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
}
data "google_compute_network" "default" {
name = "default"
required_providers {
google = {
source = "hashicorp/google"
}
}
}
resource "google_compute_subnetwork" "default" {
name = "%{resource_name}"
ip_cidr_range = "10.2.0.0/16"
network = data.google_compute_network.default.id
resource "google_bigquery_dataset" "default" {
dataset_id = "%{resource_name}"
description = "This dataset is made in an acceptance test"
}
output "%{output_name}" {
value = provider::google::%{function_name}(google_compute_subnetwork.default.self_link)
value = provider::google::%{function_name}(google_bigquery_dataset.default.self_link)
}
`, context)
}

0 comments on commit 1100d9d

Please sign in to comment.