-
Notifications
You must be signed in to change notification settings - Fork 73
Add acceptance tests and ignore no such file or directory
errors in cleaning rendered website dir
#296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add acceptance tests and ignore no such file or directory
errors in cleaning rendered website dir
#296
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
228c175
Add acceptance tests for `generate` command
SBGoods e624bce
Ignore file does not exist error when cleaning up rendered website dir.
SBGoods a3fe761
Add more template rendering unit tests
SBGoods 8908af8
Merge branch 'main' into SBGoods/acceptance-tests
SBGoods 5bbfb85
Run `go mod tidy`
SBGoods b9a26fb
Run tests from makefile
SBGoods 86b4533
Add changelog entry
SBGoods c7707c1
Add copyright headers
SBGoods 5085dd7
Add flag to skip tests for non-unix systems
SBGoods 9095948
Add unit test target
SBGoods 10c8455
Add Acceptance Testing section to Readme
SBGoods 33a8541
Move `build` package and update goreleaser `idflags`
SBGoods 3de537e
Add `.SchemaMarkdown` field and `printf` functions to Readme
SBGoods 7adb551
Add copyright headers
SBGoods 86c418d
Merge branch 'main' into SBGoods/acceptance-tests
SBGoods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
kind: BUG FIXES | ||
body: 'generate: fix `no such file or directory` error when running `generate` with | ||
no existing rendered website directory.' | ||
time: 2023-11-08T17:25:58.561956-05:00 | ||
custom: | ||
Issue: "296" |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -146,6 +146,7 @@ using the following data fields and functions: | |
| `.ProviderName` | string | Canonical provider name (ex. `terraform-provider-random`) | | ||
| `.ProviderShortName` | string | Short version of the provider name (ex. `random`) | | ||
| `.RenderedProviderName` | string | Value provided via argument `--rendered-provider-name`, otherwise same as `.ProviderName` | | ||
| `.SchemaMarkdown` | string | a Markdown formatted Provider Schema definition | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
|
||
##### Resources / Data Source | ||
|
||
|
@@ -161,6 +162,7 @@ using the following data fields and functions: | |
| `.ProviderName` | string | Canonical provider name (ex. `terraform-provider-random`) | | ||
| `.ProviderShortName` | string | Short version of the provider name (ex. `random`) | | ||
| `.RenderedProviderName` | string | Value provided via argument `--rendered-provider-name`, otherwise same as `.ProviderName` | | ||
| `.SchemaMarkdown` | string | a Markdown formatted Resource / Data Source Schema definition | | ||
|
||
#### Functions | ||
|
||
|
@@ -170,6 +172,7 @@ using the following data fields and functions: | |
| `lower` | Equivalent to [`strings.ToLower`](https://pkg.go.dev/strings#ToLower). | | ||
| `plainmarkdown` | Render Markdown content as plaintext. | | ||
| `prefixlines` | Add a prefix to all (newline-separated) lines in a string. | | ||
| `printf` | Equivalent to [`fmt.Printf`](https://pkg.go.dev/fmt#Printf). | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
| `split` | Split string into sub-strings, by a given separator (ex. `split .Name "_"`). | | ||
| `title` | Equivalent to [`cases.Title`](https://pkg.go.dev/golang.org/x/text/cases#Title). | | ||
| `tffile` | A special case of the `codefile` function, designed for Terraform files (i.e. `.tf`). | | ||
|
@@ -190,3 +193,14 @@ Your help and patience is truly appreciated. | |
All source code files in this repository (excluding autogenerated files like `go.mod`, prose, and files excluded in [.copywrite.hcl](.copywrite.hcl)) must have a license header at the top. | ||
|
||
This can be autogenerated by running `make generate` or running `go generate ./...` in the [/tools](/tools) directory. | ||
|
||
### Acceptance Tests | ||
|
||
This repo uses the `testscript` [package](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript) for acceptance testing. | ||
|
||
You can run `make testacc` to run the acceptance tests. By default, the acceptance tests will create a temporary directory in `/tmp/tftmp` for testing but you can change this location in `cmd/tfplugindocs/main_test.go` | ||
|
||
The test scripts are defined in the `tfplugindocs/testdata/scripts` directory. Each script includes the test, golden files, and the provider source code needed to run the test. | ||
|
||
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. | ||
You can also use `txtar` CLI archive files into the `.txtar` format to create new tests or modify existing ones. |
This file contains hidden or 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,18 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package build | ||
|
||
var ( | ||
// These vars will be set by goreleaser. | ||
version string = `dev` | ||
commit string = `` | ||
) | ||
|
||
func GetVersion() string { | ||
version := "tfplugindocs" + " Version " + version | ||
if commit != "" { | ||
version += " from commit " + commit | ||
} | ||
return version | ||
} |
This file contains hidden or 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 hidden or 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,40 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/rogpeppe/go-internal/testscript" | ||
|
||
"github.com/hashicorp/terraform-plugin-docs/internal/cmd" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(testscript.RunMain(m, map[string]func() int{ | ||
"tfplugindocs": cmd.Main, | ||
})) | ||
} | ||
|
||
func Test_GenerateAcceptanceTests(t *testing.T) { | ||
t.Parallel() | ||
if os.Getenv("ACCTEST") == "" { | ||
t.Skip("ACCTEST env var not set; skipping acceptance tests.") | ||
} | ||
SBGoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Setting a custom temp dir instead of relying on os.TempDir() | ||
// because Terraform providers fail to start up when $TMPDIR | ||
// length is too long: https://github.com/hashicorp/terraform/issues/32787 | ||
tmpDir := "/tmp/tftmp" | ||
SBGoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
err := os.MkdirAll(tmpDir, 0755) | ||
if err != nil { | ||
t.Errorf("Error creating temp dir for testing: %s", err.Error()) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
testscript.Run(t, testscript.Params{ | ||
Dir: "testdata/scripts/generate", | ||
WorkdirRoot: tmpDir, | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.