Expose Markdown validation selection
This commit is contained in:
@@ -192,6 +192,49 @@ func TestCheckMarkdownLinksPreservesAnchorReadCause(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunSelectsMarkdownWithCombinedGoChecksAndReportsOutOfScopeLinks(t *testing.T) {
|
||||
repository, _ := committedMarkdownTree(t, map[string][]byte{
|
||||
"guide.md": []byte("[outside](../../outside.md)\n"),
|
||||
})
|
||||
commit := strings.TrimSpace(gitTree(t, repository, "rev-parse", "HEAD"))
|
||||
goLog := installGoShim(t, "", false)
|
||||
var output bytes.Buffer
|
||||
err := Run(context.Background(), Request{
|
||||
RepositoryDir: repository,
|
||||
Commit: commit,
|
||||
Output: &output,
|
||||
Settings: Settings{
|
||||
Race: true,
|
||||
FullVet: true,
|
||||
CompileTargets: []Target{{OS: "linux", Arch: "amd64"}},
|
||||
Markdown: &MarkdownSettings{},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v, want out-of-scope observation to succeed", err)
|
||||
}
|
||||
if got := output.String(); !strings.Contains(got, "outside the checkout") || !strings.Contains(got, "out of scope") {
|
||||
t.Fatalf("Run() output = %q, want outside-checkout observation", got)
|
||||
}
|
||||
commands := readGoShimLog(t, goLog)
|
||||
var testCommands []string
|
||||
var validationCommands []string
|
||||
for _, command := range commands {
|
||||
if strings.HasPrefix(command, "test ") {
|
||||
testCommands = append(testCommands, command)
|
||||
}
|
||||
if strings.HasPrefix(command, "test ") || strings.HasPrefix(command, "vet ") || strings.HasPrefix(command, "build ") {
|
||||
validationCommands = append(validationCommands, command)
|
||||
}
|
||||
}
|
||||
if len(testCommands) != 1 || !strings.Contains(testCommands[0], "-race") || !strings.Contains(testCommands[0], "-vet=off") {
|
||||
t.Fatalf("Go test commands = %#v, want one race-enabled suite with test-time vet disabled", testCommands)
|
||||
}
|
||||
if len(validationCommands) != 3 || !strings.HasPrefix(validationCommands[0], "test ") || !strings.HasPrefix(validationCommands[1], "vet ") || !strings.HasPrefix(validationCommands[2], "build ") {
|
||||
t.Fatalf("Go validation commands = %#v, want test, full vet, and target compilation before Markdown", validationCommands)
|
||||
}
|
||||
}
|
||||
|
||||
func committedMarkdownTree(t *testing.T, files map[string][]byte) (string, *CandidateTree) {
|
||||
t.Helper()
|
||||
repository := newTreeRepository(t)
|
||||
|
||||
@@ -20,10 +20,16 @@ type Settings struct {
|
||||
FullVet bool
|
||||
CompileTargets []Target
|
||||
GoFormat bool
|
||||
Markdown *MarkdownSettings
|
||||
ModuleDistribution ModuleDistributionSettings
|
||||
FileSize *FileSizeSettings
|
||||
}
|
||||
|
||||
// MarkdownSettings selects committed Markdown destination and fragment checks.
|
||||
type MarkdownSettings struct {
|
||||
EnforceCheckoutBoundary bool
|
||||
}
|
||||
|
||||
// FileSizeSettings selects a per-blob limit and literal path exclusions.
|
||||
type FileSizeSettings struct {
|
||||
LimitBytes *int64
|
||||
@@ -112,10 +118,13 @@ func Run(ctx context.Context, request Request) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if request.Settings.GoFormat || request.Settings.ModuleDistribution.WorkspaceFiles || request.Settings.ModuleDistribution.LocalReplacements || request.Settings.FileSize != nil {
|
||||
if request.Settings.GoFormat || request.Settings.ModuleDistribution.WorkspaceFiles || request.Settings.ModuleDistribution.LocalReplacements || request.Settings.FileSize != nil || request.Settings.Markdown != nil {
|
||||
tree, err := request.ReadCandidateTree(ctx)
|
||||
if err != nil {
|
||||
check := FileSize
|
||||
check := MarkdownLinks
|
||||
if request.Settings.FileSize != nil {
|
||||
check = FileSize
|
||||
}
|
||||
if request.Settings.ModuleDistribution.LocalReplacements {
|
||||
check = LocalReplacements
|
||||
}
|
||||
@@ -147,6 +156,11 @@ func Run(ctx context.Context, request Request) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if request.Settings.Markdown != nil {
|
||||
if err := checkMarkdownLinks(ctx, tree, request.Settings.Markdown.EnforceCheckoutBoundary, request.Output); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user