Skip to content

Commit

Permalink
Add more regex filters to installation docsgen (#2421)
Browse files Browse the repository at this point in the history
Rather than handling these in individual providers, they're best served
here.

Adds a few test cases to guard against any regression.

- **Match TF mentions found in gitlab provider and add test cases**
- **Add a header to skip as seen in hcloud**
  • Loading branch information
guineveresaenger authored Sep 19, 2024
1 parent cd77457 commit 9668009
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/tfgen/installation_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,16 @@ func getDefaultHeadersToSkip() []*regexp.Regexp {
regexp.MustCompile("[Dd]ebugging"),
regexp.MustCompile("[Tt]erraform CLI"),
regexp.MustCompile("[Tt]erraform Cloud"),
regexp.MustCompile("Delete Protection"),
}
return defaultHeaderSkipRegexps
}

func getTfVersionsToRemove() []*regexp.Regexp {
tfVersionsToRemove := []*regexp.Regexp{
regexp.MustCompile(`It requires [tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]? or later.`),
regexp.MustCompile(`(It|This provider) requires( at least)? [tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]?( or later)?.`),
regexp.MustCompile(`(?s)(For )?[tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]? and (later|earlier):`),
regexp.MustCompile(`A minimum of [tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]? is recommended.`),
}
return tfVersionsToRemove
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/tfgen/installation_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,34 @@ func TestApplyEditRules(t *testing.T) {
},
expected: []byte("This is a provider with an example.\nUse this code."),
},
{
name: "Strips mentions of Terraform version pattern 6",
docFile: DocFile{
Content: []byte("This provider requires at least Terraform 1.0."),
},
expected: []byte(""),
},
{
name: "Strips mentions of Terraform version pattern 7",
docFile: DocFile{
Content: []byte("This provider requires Terraform 1.0."),
},
expected: []byte(""),
},
{
name: "Strips mentions of Terraform version pattern 8",
docFile: DocFile{
Content: []byte("A minimum of Terraform 1.4.0 is recommended."),
},
expected: []byte(""),
},
{
name: "Strips mentions of Terraform version With Surrounding Text",
docFile: DocFile{
Content: []byte(readfile(t, "test_data/replace-terraform-version/input.md")),
},
expected: []byte(readfile(t, "test_data/replace-terraform-version/expected.md")),
},
}
for _, tt := range tests {
tt := tt
Expand Down
11 changes: 11 additions & 0 deletions pkg/tfgen/test_data/replace-terraform-version/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Use the GitLab provider to interact with GitLab resources, like
users, groups, projects and more. You must configure the provider with
the proper credentials before you can use it.

The provider uses the [`xanzy/go-gitlab`](https://github.com/xanzy/go-gitlab) library
to interact with the [GitLab REST API](https://docs.gitlab.com/ee/api/api_resources.html).

Each data source and resource references the appropriate upstream GitLab REST API documentation,
which may be consumed to better understand the behavior of the API.

Use the navigation to the left to read about the valid data sources and resources.
16 changes: 16 additions & 0 deletions pkg/tfgen/test_data/replace-terraform-version/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Use the GitLab provider to interact with GitLab resources, like
users, groups, projects and more. You must configure the provider with
the proper credentials before you can use it.

The provider uses the [`xanzy/go-gitlab`](https://github.com/xanzy/go-gitlab) library
to interact with the [GitLab REST API](https://docs.gitlab.com/ee/api/api_resources.html).

This provider requires Terraform 1.0.

Each data source and resource references the appropriate upstream GitLab REST API documentation,
which may be consumed to better understand the behavior of the API.

Use the navigation to the left to read about the valid data sources and resources.

This provider requires at least [Terraform 1.0](https://www.terraform.io/downloads.html).
A minimum of Terraform 1.4.0 is recommended.

0 comments on commit 9668009

Please sign in to comment.