Skip to content

Commit 2e6a2c4

Browse files
Replace the usage of Nprinf (#8231) (#5833)
Signed-off-by: Modular Magician <[email protected]>
1 parent 876b26f commit 2e6a2c4

File tree

602 files changed

+1907
-1916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

602 files changed

+1907
-1916
lines changed

.changelog/8231.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/acctest/test_utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package acctest
55
import (
66
"errors"
77
"fmt"
8+
"strings"
89

910
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1011
)
@@ -56,3 +57,14 @@ func CheckDataSourceStateMatchesResourceStateWithIgnores(dataSourceName, resourc
5657
return nil
5758
}
5859
}
60+
61+
// This is a Printf sibling (Nprintf; Named Printf), which handles strings like
62+
// Nprintf("Hello %{target}!", map[string]interface{}{"target":"world"}) == "Hello world!".
63+
// This is particularly useful for generated tests, where we don't want to use Printf,
64+
// since that would require us to generate a very particular ordering of arguments.
65+
func Nprintf(format string, params map[string]interface{}) string {
66+
for key, val := range params {
67+
format = strings.Replace(format, "%{"+key+"}", fmt.Sprintf("%v", val), -1)
68+
}
69+
return format
70+
}

google-beta/data_source_access_approval_folder_service_account_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestAccDataSourceAccessApprovalFolderServiceAccount_basic(t *testing.T) {
3838
}
3939

4040
func testAccDataSourceAccessApprovalFolderServiceAccount_basic(context map[string]interface{}) string {
41-
return Nprintf(`
41+
return acctest.Nprintf(`
4242
resource "google_folder" "my_folder" {
4343
display_name = "tf-test-my-folder%{random_suffix}"
4444
parent = "organizations/%{org_id}"

google-beta/data_source_access_approval_organization_service_account_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccDataSourceAccessApprovalOrganizationServiceAccount_basic(t *testing.
3434
}
3535

3636
func testAccDataSourceAccessApprovalOrganizationServiceAccount_basic(context map[string]interface{}) string {
37-
return Nprintf(`
37+
return acctest.Nprintf(`
3838
data "google_access_approval_organization_service_account" "aa_account" {
3939
organization_id = "%{org_id}"
4040
}

google-beta/data_source_access_approval_project_service_account_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccDataSourceAccessApprovalProjectServiceAccount_basic(t *testing.T) {
3434
}
3535

3636
func testAccDataSourceAccessApprovalProjectServiceAccount_basic(context map[string]interface{}) string {
37-
return Nprintf(`
37+
return acctest.Nprintf(`
3838
data "google_access_approval_project_service_account" "aa_account" {
3939
project_id = "%{project_id}"
4040
}

google-beta/data_source_alloydb_locations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestAccDataSourceAlloydbLocations_basic(t *testing.T) {
3838
}
3939

4040
func testAccDataSourceAlloydbLocations_basic(context map[string]interface{}) string {
41-
return Nprintf(`
41+
return acctest.Nprintf(`
4242
data "google_alloydb_locations" "qa" {
4343
}
4444
`, context)

google-beta/data_source_alloydb_supported_database_flags_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestAccDataSourceAlloydbSupportedDatabaseFlags_basic(t *testing.T) {
3737
}
3838

3939
func testAccDataSourceAlloydbSupportedDatabaseFlags_basic(context map[string]interface{}) string {
40-
return Nprintf(`
40+
return acctest.Nprintf(`
4141
data "google_alloydb_supported_database_flags" "qa" {
4242
location = "us-central1"
4343
}

google-beta/data_source_artifact_registry_repository_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccDataSourceGoogleArtifactRegistryRepositoryConfig(t *testing.T) {
3434
}
3535

3636
func testAccDataSourceGoogleArtifactRegistryRepositoryConfig(context map[string]interface{}) string {
37-
return Nprintf(`
37+
return acctest.Nprintf(`
3838
resource "google_artifact_registry_repository" "my-repo" {
3939
location = "us-central1"
4040
repository_id = "tf-test-my-repository%{random_suffix}"

google-beta/data_source_certificate_authority_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccDataSourcePrivatecaCertificateAuthority_privatecaCertificateAuthorit
3434
}
3535

3636
func testAccDataSourcePrivatecaCertificateAuthority_privatecaCertificateAuthorityBasicExample(context map[string]interface{}) string {
37-
return Nprintf(`
37+
return acctest.Nprintf(`
3838
resource "google_privateca_certificate_authority" "default" {
3939
// This example assumes this pool already exists.
4040
// Pools cannot be deleted in normal test circumstances, so we depend on static pools

google-beta/data_source_cloud_identity_group_memberships_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func testAccDataSourceCloudIdentityGroupMemberships_basicTest(t *testing.T) {
1919
"random_suffix": RandString(t, 10),
2020
}
2121

22-
memberId := Nprintf("%{identity_user}@%{org_domain}", context)
22+
memberId := acctest.Nprintf("%{identity_user}@%{org_domain}", context)
2323

2424
VcrTest(t, resource.TestCase{
2525
PreCheck: func() { acctest.AccTestPreCheck(t) },
@@ -41,7 +41,7 @@ func testAccDataSourceCloudIdentityGroupMemberships_basicTest(t *testing.T) {
4141
}
4242

4343
func testAccCloudIdentityGroupMembershipConfig(context map[string]interface{}) string {
44-
return testAccCloudIdentityGroupMembership_cloudIdentityGroupMembershipUserExample(context) + Nprintf(`
44+
return testAccCloudIdentityGroupMembership_cloudIdentityGroupMembershipUserExample(context) + acctest.Nprintf(`
4545
4646
data "google_cloud_identity_group_memberships" "members" {
4747
group = google_cloud_identity_group_membership.cloud_identity_group_membership_basic.group

0 commit comments

Comments
 (0)