From 72b45c2e27174b6d1c92a97633ce4e8fca2b60ee Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Tue, 15 Aug 2023 11:20:38 -0700 Subject: [PATCH] Modify the tests doc to point to service folder for tests (#8628) --- docs/content/develop/resource.md | 4 ++-- docs/content/develop/run-tests.md | 4 ++-- docs/content/develop/test.md | 6 +++--- docs/content/get-started/how-magic-modules-works.md | 4 ++-- mmv1/provider/terraform/common~compile.yaml | 5 ----- mmv1/provider/terraform/common~copy.yaml | 7 ------- .../constants/resource_dns_resource_record_set.go.erb | 2 +- .../terraform/services/dns/resource_dns_record_set.go | 2 +- 8 files changed, 11 insertions(+), 23 deletions(-) diff --git a/docs/content/develop/resource.md b/docs/content/develop/resource.md index 168299aa7e6f..ac3f804a519b 100644 --- a/docs/content/develop/resource.md +++ b/docs/content/develop/resource.md @@ -193,7 +193,7 @@ For more information about types of resources and the generation process overall 3. From the beta provider, copy the files generated for the resource to the following locations: - Resource: Copy to the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) - Documentation: [`magic-modules/mmv1/third_party/terraform/website/docs/r`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/r) - - Tests: [`magic-modules/mmv1/third_party/terraform/tests`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests), and remove `_generated` from the filename + - Tests: Copy to the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services), and remove `_generated` from the filename - Sweepers: [`magic-modules/mmv1/third_party/terraform/utils`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/utils) 4. Modify the Go code as needed. - Replace all occurrences of `github.com/hashicorp/terraform-provider-google-beta/google-beta` with `github.com/hashicorp/terraform-provider-google/google` @@ -422,7 +422,7 @@ iam_policy: !ruby/object:Api::Resource::IamPolicy 2. From the beta provider, copy the files generated for the IAM resources to the following locations: - Resource: Copy to the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) - Documentation: [`magic-modules/mmv1/third_party/terraform/website/docs/r`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/r) - - Tests: [`magic-modules/mmv1/third_party/terraform/tests`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) + - Tests: In the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) 3. Modify the Go code as needed. - Replace all occurrences of `github.com/hashicorp/terraform-provider-google-beta/google-beta` with `github.com/hashicorp/terraform-provider-google/google` - Remove the comments at the top of the file. diff --git a/docs/content/develop/run-tests.md b/docs/content/develop/run-tests.md index 7aa0b932f98e..71de5c475146 100644 --- a/docs/content/develop/run-tests.md +++ b/docs/content/develop/run-tests.md @@ -59,7 +59,7 @@ aliases: 1. Run acceptance tests for only modified resources. (Full test runs can take over 9 hours.) See [Go's documentation](https://pkg.go.dev/cmd/go#hdr-Testing_flags) for more information about `-run` and other flags. ```bash - make testacc TEST=./google TESTARGS='-run=TestAccContainerNodePool' + make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool' ``` @@ -67,7 +67,7 @@ aliases: 1. Optional: Save verbose test output to a file for analysis. ```bash - TF_LOG=TRACE make testacc TEST=./google TESTARGS='-run=TestAccContainerNodePool_basic' > output.log + TF_LOG=TRACE make testacc TEST=./google/services/container TESTARGS='-run=TestAccContainerNodePool_basic' > output.log ``` 1. Optional: Debug tests with [Delve](https://github.com/go-delve/delve). See [`dlv test` documentation](https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_test.md) for information about available flags. diff --git a/docs/content/develop/test.md b/docs/content/develop/test.md index 7e4b2da469b6..b0d5100886b8 100644 --- a/docs/content/develop/test.md +++ b/docs/content/develop/test.md @@ -94,7 +94,7 @@ This section assumes you've used the [Add a resource]({{< ref "/develop/resource 1. Add the test in MMv1. Repeat for all the create tests you will need. 2. [Generate the beta provider]({{< ref "/get-started/generate-providers.md" >}}). -3. From the beta provider, copy and paste the generated `*_generated_test.go` file into [`magic-modules/mmv1/third_party/terraform/tests`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) as a new file call `*_test.go`. +3. From the beta provider, copy and paste the generated `*_generated_test.go` file into the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/) as a new file call `*_test.go`. 4. Modify the tests as needed. - Replace all occurrences of `github.com/hashicorp/terraform-provider-google-beta/google-beta` with `github.com/hashicorp/terraform-provider-google/google` - Remove the comments at the top of the file. @@ -115,7 +115,7 @@ An update test is a test that creates the target resource and then makes updates {{< tabs "update" >}} {{< tab "MMv1" >}} 1. [Generate the beta provider]({{< ref "/get-started/generate-providers.md" >}}). -2. From the beta provider, copy and paste the generated `*_generated_test.go` file into [`magic-modules/mmv1/third_party/terraform/tests`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) as a new file call `*_test.go`. +2. From the beta provider, copy and paste the generated `*_generated_test.go` file into the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) as a new file call `*_test.go`. 3. Using an editor of your choice, delete the `*DestroyProducer` function, and all but one test. The remaining test should be the "full" test, or if there is no "full" test, the "basic" test. This will be the starting point for your new update test. 4. Modify the `TestAcc*` *test function* to support updates. - Change the suffix of the test function to `_update`. @@ -171,7 +171,7 @@ An update test is a test that creates the target resource and then makes updates - In each beta-only test, ensure that all Terraform resources in all configs have `provider = google-beta` set {{< /tab >}} {{< tab "Handwritten" >}} -1. Using an editor of your choice, open the existing `*_test.go` or `*_test.go.erb` file in [`magic-modules/mmv1/third_party/terraform/tests`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) which contains your create tests. +1. Using an editor of your choice, open the existing `*_test.go` or `*_test.go.erb` file in the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) which contains your create tests. 2. Copy the `TestAcc*` *test function* for the existing "full" test. If there is no "full" test, use the "basic" test. This will be the starting point for your new update test. 3. Modify the test function to support updates. - Change the suffix of the test function to `_update`. diff --git a/docs/content/get-started/how-magic-modules-works.md b/docs/content/get-started/how-magic-modules-works.md index 3eb58b998e87..f38bf757607c 100644 --- a/docs/content/get-started/how-magic-modules-works.md +++ b/docs/content/get-started/how-magic-modules-works.md @@ -22,7 +22,7 @@ MMv1 consists of a set of "products"; each product contains one or more "resourc Each product has a folder in [`magic-modules/mmv1/products`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products). The name of the folder is the "product name", which usually corresponds to the API subdomain covered by the product (such as `compute.googleapis.com`). Each product folder contains a product configuration file (`product.yaml`) and one or more resource configuration files (`ResourceName.yaml`). The actual name of a `ResourceName.yaml` file usually matches the name of a GCP API resource in the product's subdomain. -MMv1 resource configurations may reference handwritten code stored in [`magic-modules/mmv1/templates/terraform`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform), which will be injected into the generated resource file. Many MMv1 resources also have one or more handwritten tests, which are stored in [`magic-modules/mmv1/third_party/terraform/tests`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) +MMv1 resource configurations may reference handwritten code stored in [`magic-modules/mmv1/templates/terraform`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform), which will be injected into the generated resource file. Many MMv1 resources also have one or more handwritten tests, which are stored in the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) In the providers, MMv1-based resources are stored in `PROVIDER/services/PRODUCT/resource_PRODUCT_RESOURCE.go`, where `PROVIDER` is `google` or `google-beta`, `PRODUCT` is the product name, and RESOURCE is the GCP API resource's name converted to [snake case ↗](https://en.wikipedia.org/wiki/Snake_case). @@ -43,7 +43,7 @@ In addition to the core implementation, handwritten resources and datasources wi - Resource & datasource implementation: In the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) - Resource documentation: [`magic-modules/mmv1/third_party/terraform/website/docs/r`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/r) - Datasource documentation: [`magic-modules/mmv1/third_party/terraform/webside/docs/d`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/webside/docs/d) -- Tests: [`magic-modules/mmv1/third_party/terraform/tests`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) +- Tests: In the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) - Sweepers: [`magic-modules/mmv1/third_party/terraform/utils`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/utils) In the providers, handwritten resources and datasources are stored in `PROVIDER/services/SERVICE/FILENAME.go`, where `PROVIDER` is `google` or `google-beta`, `SERVICE` is the service name, and `FILENAME` is the name of the handwritten file in magic-modules. Handwritten files do not have an `AUTO GENERATED CODE` header. diff --git a/mmv1/provider/terraform/common~compile.yaml b/mmv1/provider/terraform/common~compile.yaml index e0db78213803..5414cd1ce936 100644 --- a/mmv1/provider/terraform/common~compile.yaml +++ b/mmv1/provider/terraform/common~compile.yaml @@ -26,11 +26,6 @@ <% end -%> <% end -%> -<% Dir["third_party/terraform/tests/*.go.erb"].each do |file_path| - fname = file_path.split('/')[-1] --%> -'<%= dir -%>/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/tests/<%= fname -%>' -<% end -%> <% Dir["third_party/terraform/resources/*.go.erb"].each do |file_path| fname = file_path.split('/')[-1] diff --git a/mmv1/provider/terraform/common~copy.yaml b/mmv1/provider/terraform/common~copy.yaml index 6f89b429a50b..854430e1a21c 100644 --- a/mmv1/provider/terraform/common~copy.yaml +++ b/mmv1/provider/terraform/common~copy.yaml @@ -31,13 +31,6 @@ <% end -%> <% end -%> -# Handwritten acceptance tests for autogenerated resources. -# Adding them here allows updating the tests as part of a MM pull request. -<% Dir["third_party/terraform/tests/*.go"].each do |file_path| - fname = file_path.split('/')[-1] --%> -'<%= dir -%>/<%= fname -%>': 'third_party/terraform/tests/<%= fname -%>' -<% end -%> # Copy all of the terraform resources that are still hand written <% Dir["third_party/terraform/resources/*.go"].each do |file_path| diff --git a/mmv1/templates/terraform/constants/resource_dns_resource_record_set.go.erb b/mmv1/templates/terraform/constants/resource_dns_resource_record_set.go.erb index 58b511869be2..3fe62eb8782b 100644 --- a/mmv1/templates/terraform/constants/resource_dns_resource_record_set.go.erb +++ b/mmv1/templates/terraform/constants/resource_dns_resource_record_set.go.erb @@ -25,7 +25,7 @@ func rrdatasDnsDiffSuppress(k, old, new string, d *schema.ResourceData) bool { // suppress on a list when 1) its items have dups that need to be ignored // and 2) string comparison on the items may need a special parse function -// example of usage can be found ../../../third_party/terraform/tests/resource_dns_record_set_test.go.erb +// example of usage can be found ../../../third_party/terraform/services/dns/resource_dns_record_set_test.go.erb func RrdatasListDiffSuppress(oldList, newList []string, fun func(x string) string, _ *schema.ResourceData) bool { // compare two lists of unordered records diff := make(map[string]bool, len(oldList)) diff --git a/mmv1/third_party/terraform/services/dns/resource_dns_record_set.go b/mmv1/third_party/terraform/services/dns/resource_dns_record_set.go index 5ce73f120c69..cd858785d8c7 100644 --- a/mmv1/third_party/terraform/services/dns/resource_dns_record_set.go +++ b/mmv1/third_party/terraform/services/dns/resource_dns_record_set.go @@ -46,7 +46,7 @@ func rrdatasDnsDiffSuppress(k, old, new string, d *schema.ResourceData) bool { // suppress on a list when 1) its items have dups that need to be ignored // and 2) string comparison on the items may need a special parse function -// example of usage can be found ../../../third_party/terraform/tests/resource_dns_record_set_test.go.erb +// example of usage can be found ../../../third_party/terraform/services/dns/resource_dns_record_set_test.go.erb func RrdatasListDiffSuppress(oldList, newList []string, fun func(x string) string, _ *schema.ResourceData) bool { // compare two lists of unordered records diff := make(map[string]bool, len(oldList))