You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
body: 'generate: The `.ProviderShortName` template function now uses the rendered provider name to derive the provider short name. Users that pass in the
3
-
`--rendered-provider-name` flag might see a different output for this function'
3
+
`--rendered-provider-name` flag might see a different output for this function'
Copy file name to clipboardExpand all lines: README.md
+76-31Lines changed: 76 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -223,16 +223,17 @@ For examples:
223
223
> **NOTE:** In the following conventional paths for examples, `<data source name>` and `<resource name>` include the provider prefix as well, but the provider prefix is **NOT** included in`<function name>`.
224
224
> For example, the data source [`caller_identity`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) in the `aws` provider would have an "example" conventional path of: `examples/data-sources/aws_caller_identity/data-source.tf`
| `.ProviderShortName` | string | Short version of the rendered provider name (ex. `random`) |
313
+
| `.RenderedProviderName` | string | Value provided via argument `--rendered-provider-name`, otherwise same as `.ProviderName` |
314
+
| `.SchemaMarkdown` | string | a Markdown formatted Resource / Data Source Schema definition |
311
315
312
316
##### Provider-defined Function Fields
313
317
@@ -360,16 +364,57 @@ This can be autogenerated by running `make generate` or running `go generate ./.
360
364
### Acceptance Tests
361
365
362
366
This repo uses the `testscript` [package](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript) for acceptance testing.
363
-
364
367
There are two types of acceptance tests: full provider build tests in`tfplugindocs/testdata/scripts/provider-build` and provider schema json tests in`tfplugindocs/testdata/scripts/schema-json`.
365
368
366
-
Provider build tests run the default `tfplugindocs`command which builds the provider source code and runs Terraform to retrieve the schema. These tests require the full provider source code to build a valid provider binary.
367
-
368
-
Schema json tests run the `tfplugindocs`command with the `--providers-schema=<arg>` flag to specify a provider schemas json file. This allows the test to skip the provider build and Terraform CLI call, instead using the specified file to generate docs.
369
+
Provider [build tests](./cmd/tfplugindocs/testdata/scripts/provider-build/) run the default `tfplugindocs`command which builds the provider source code and runs Terraform to retrieve the schema. These tests require the full provider source code to build a valid provider binary.
370
+
[Schema json](./cmd/tfplugindocs/testdata/scripts/schema-json/) tests run the `tfplugindocs`command with the `--providers-schema=<arg>` flag to specify a provider schemas json file. This allows the test to skip the provider build and Terraform CLI call, instead using the specified file to generate docs.
369
371
370
372
You can run `make testacc` to run the full suite of acceptance tests. By default, the provider build acceptance tests will create a temporary directory in`/tmp/tftmp`fortesting, but you can change this locationin`cmd/tfplugindocs/main_test.go`. The schema json tests uses the `testscript` package's [default work directory](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript#Params.WorkdirRoot).
371
373
372
374
The test scripts are defined in the `tfplugindocs/testdata/scripts` directory. Each script includes the test, golden files, and the provider source code or schema JSON file needed to run the test.
375
+
Each script is a [text archive](https://pkg.go.dev/golang.org/x/tools/txtar). You can install the `txtar` CLI locally by running `go install golang.org/x/exp/cmd/txtar@latest` to extract the files in the test script for debugging or to help with updating.
376
+
377
+
For example, to unarchive all of the files from a test script:
378
+
```bash
379
+
# Assuming that your working directory is the root of the terraform-plugin-docs repo
380
+
381
+
# Create a fresh directory to extract to
382
+
mkdir tmp && cd tmp
383
+
384
+
# Extract this specific test script to the current working directory
Each script is a [text archive](https://pkg.go.dev/golang.org/x/tools/txtar). You can install the `txtar` CLI locally by running `go install golang.org/x/exp/cmd/txtar@latest` to extract the files in the test script for debugging.
375
-
You can also use `txtar` CLI archive files into the `.txtar` format to create new tests or modify existing ones.
405
+
Once a new text archive is created, the comment header can be replaced with [test script commands](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript)
406
+
like `env`, `cmp`, `exec`, etc. These commands control what actually is run during the test along with the assertions, for example:
407
+
```bash
408
+
# Copyright (c) HashiCorp, Inc.
409
+
# SPDX-License-Identifier: MPL-2.0
410
+
411
+
# Successful run of tfplugindocs on a Framework provider with examples but no templates or pre-existing docs.
412
+
[!unix] skip
413
+
env GOCACHE=$WORK/gocache # sets an environment variable
414
+
env GOMODCACHE=$WORK/gomodcache # sets an environment variable
415
+
exec tfplugindocs --provider-name=terraform-provider-scaffolding # executes the Go binary for generating documentation
416
+
cmp stdout expected-output.txt # compares stdout from binary with the golden file in the text archive below
417
+
cmp docs/index.md expected-index.md # compares the generated docs with the golden file in the text archive below
418
+
cmp docs/data-sources/example.md expected-datasource.md # compares the generated docs with the golden file in the text archive below
419
+
cmp docs/resources/example.md expected-resource.md # compares the generated docs with the golden file in the text archive below
0 commit comments