Skip to content

Commit c7d6bc1

Browse files
Add test to check that default headers are skipped
These tests will fail when default headers are removed from the denylist in getDefaultHeadersToSkip.
1 parent 5dfc814 commit c7d6bc1

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

pkg/tfgen/installation_docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func getDefaultHeadersToSkip() []*regexp.Regexp {
400400
regexp.MustCompile("[Dd]evelopment"),
401401
regexp.MustCompile("[Dd]ebugging"),
402402
regexp.MustCompile("[Tt]erraform CLI"),
403-
regexp.MustCompile("[Tt]erraform Cloud"),
403+
regexp.MustCompile("[Tt]erraform [Cc]loud"),
404404
regexp.MustCompile("Delete Protection"),
405405
regexp.MustCompile("[Cc]ontributing"),
406406
}

pkg/tfgen/installation_docs_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tfgen
22

33
import (
44
"bytes"
5+
"regexp"
56
"runtime"
67
"testing"
78

@@ -396,6 +397,94 @@ func TestSkipSectionHeadersByContent(t *testing.T) {
396397
})
397398
}
398399

400+
func TestSkipDefaultSectionHeaders(t *testing.T) {
401+
t.Parallel()
402+
type testCase struct {
403+
// The name of the test case.
404+
name string
405+
headersToSkip []*regexp.Regexp
406+
input string
407+
expected string
408+
}
409+
410+
testCases := []testCase{
411+
{
412+
name: "Skips Sections Mentioning Logging",
413+
headersToSkip: getDefaultHeadersToSkip(),
414+
input: "## Logging",
415+
expected: "",
416+
},
417+
{
418+
name: "Skips Sections Mentioning Logs",
419+
headersToSkip: getDefaultHeadersToSkip(),
420+
input: "## This section talks about logs",
421+
expected: "",
422+
},
423+
{
424+
name: "Skips Sections About Testing",
425+
headersToSkip: getDefaultHeadersToSkip(),
426+
input: "## Testing",
427+
expected: "",
428+
},
429+
{
430+
name: "Skips Sections About Development",
431+
headersToSkip: getDefaultHeadersToSkip(),
432+
input: "## Development",
433+
expected: "",
434+
},
435+
{
436+
name: "Skips Sections About Debugging",
437+
headersToSkip: getDefaultHeadersToSkip(),
438+
input: "## Debugging",
439+
expected: "",
440+
},
441+
{
442+
name: "Skips Sections Talking About Terraform CLI",
443+
headersToSkip: getDefaultHeadersToSkip(),
444+
input: "## Terraform CLI",
445+
expected: "",
446+
},
447+
{
448+
name: "Skips Sections Talking About terraform cloud",
449+
headersToSkip: getDefaultHeadersToSkip(),
450+
input: "### terraform cloud",
451+
expected: "",
452+
},
453+
{
454+
name: "Skips Sections About Delete Protection",
455+
headersToSkip: getDefaultHeadersToSkip(),
456+
input: "### Delete Protection",
457+
expected: "",
458+
}, {
459+
name: "Skips Sections About Contributing",
460+
headersToSkip: getDefaultHeadersToSkip(),
461+
input: "## Contributing",
462+
expected: "",
463+
}, {
464+
name: "Does Not Skip Sections About Unicorns",
465+
headersToSkip: getDefaultHeadersToSkip(),
466+
input: "## Unicorns",
467+
expected: "## Unicorns",
468+
},
469+
}
470+
for _, tt := range testCases {
471+
tt := tt
472+
t.Run(tt.name, func(t *testing.T) {
473+
t.Parallel()
474+
actual, err := SkipSectionByHeaderContent([]byte(tt.input), func(headerText string) bool {
475+
for _, header := range tt.headersToSkip {
476+
if header.Match([]byte(headerText)) {
477+
return true
478+
}
479+
}
480+
return false
481+
})
482+
require.NoError(t, err)
483+
assertEqualHTML(t, tt.expected, string(actual))
484+
})
485+
}
486+
}
487+
399488
// Helper func to determine if the HTML rendering is equal.
400489
// This helps in cases where the processed Markdown is slightly different from the expected Markdown
401490
// due to goldmark making some (insignificant to the final HTML) changes when parsing and rendering.

0 commit comments

Comments
 (0)