Check committed Go formatting
This commit is contained in:
@@ -12,10 +12,10 @@ func TestCandidateRequestMapsGoValidation(t *testing.T) {
|
||||
Validation: ValidationSpec{Go: GoValidationSpec{
|
||||
Race: true, FullVet: true,
|
||||
CompileTargets: []Target{{OS: "linux", Arch: "amd64"}, {OS: "darwin", Arch: "arm64"}},
|
||||
}},
|
||||
}, GoFormat: true},
|
||||
})
|
||||
if !request.Validation.Race || !request.Validation.FullVet {
|
||||
t.Fatalf("candidate request validation = %#v, want race and full vet enabled", request.Validation)
|
||||
if !request.Validation.Race || !request.Validation.FullVet || !request.Validation.GoFormat {
|
||||
t.Fatalf("candidate request validation = %#v, want race, full vet, and formatting enabled", request.Validation)
|
||||
}
|
||||
want := []validation.Target{{OS: "linux", Arch: "amd64"}, {OS: "darwin", Arch: "arm64"}}
|
||||
if len(request.Validation.CompileTargets) != len(want) {
|
||||
@@ -39,3 +39,25 @@ func TestValidationErrorPreservesGoVetIdentity(t *testing.T) {
|
||||
t.Fatalf("converted error = %v, want cause preserved", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidationErrorPreservesGoFormatIdentityAndFindings(t *testing.T) {
|
||||
cause := errors.New("format parser failed")
|
||||
got := convertValidationError(&validation.Failure{
|
||||
Check: validation.GoFormat,
|
||||
Findings: []validation.Finding{{
|
||||
Path: "vendor/example/bad.go",
|
||||
Message: "committed Go source cannot be formatted",
|
||||
}},
|
||||
Cause: cause,
|
||||
})
|
||||
var validationError *ValidationError
|
||||
if !errors.As(got, &validationError) || validationError.Check != "go-format" {
|
||||
t.Fatalf("converted error = %#v, want go-format validation identity", got)
|
||||
}
|
||||
if len(validationError.Findings) != 1 || validationError.Findings[0].Path != "vendor/example/bad.go" {
|
||||
t.Fatalf("converted findings = %#v, want vendor path", validationError.Findings)
|
||||
}
|
||||
if !errors.Is(got, cause) {
|
||||
t.Fatalf("converted error = %v, want parser cause preserved", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user