81 lines
3.2 KiB
Go
81 lines
3.2 KiB
Go
package releasekit
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/ReleaseKit/internal/validation"
|
|
)
|
|
|
|
func TestCandidateRequestMapsGoValidation(t *testing.T) {
|
|
request := candidateRequest(ReleaseRequest{
|
|
Validation: ValidationSpec{Go: GoValidationSpec{
|
|
Race: true, FullVet: true,
|
|
CompileTargets: []Target{{OS: "linux", Arch: "amd64"}, {OS: "darwin", Arch: "arm64"}},
|
|
}, GoFormat: true, ModuleDistribution: ModuleDistributionValidationSpec{WorkspaceFiles: true}},
|
|
})
|
|
if !request.Validation.Race || !request.Validation.FullVet || !request.Validation.GoFormat || !request.Validation.ModuleDistribution.WorkspaceFiles {
|
|
t.Fatalf("candidate request validation = %#v, want race, full vet, formatting, and workspace inspection enabled", request.Validation)
|
|
}
|
|
want := []validation.Target{{OS: "linux", Arch: "amd64"}, {OS: "darwin", Arch: "arm64"}}
|
|
if len(request.Validation.CompileTargets) != len(want) {
|
|
t.Fatalf("candidate request compile targets = %#v, want %#v", request.Validation.CompileTargets, want)
|
|
}
|
|
for index := range want {
|
|
if request.Validation.CompileTargets[index] != want[index] {
|
|
t.Fatalf("candidate request compile targets = %#v, want %#v", request.Validation.CompileTargets, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidationErrorPreservesGoVetIdentity(t *testing.T) {
|
|
cause := errors.New("vet failed")
|
|
got := convertValidationError(&validation.Failure{Check: validation.GoVet, Cause: cause})
|
|
var validationError *ValidationError
|
|
if !errors.As(got, &validationError) || validationError.Check != "go-vet" {
|
|
t.Fatalf("converted error = %#v, want go-vet validation identity", got)
|
|
}
|
|
if !errors.Is(got, cause) {
|
|
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)
|
|
}
|
|
}
|
|
|
|
func TestValidationErrorPreservesWorkspaceFilesIdentity(t *testing.T) {
|
|
got := convertValidationError(&validation.Failure{
|
|
Check: validation.WorkspaceFiles,
|
|
Findings: []validation.Finding{{
|
|
Path: "nested/go.work.sum",
|
|
Message: "workspace file is committed in the candidate",
|
|
}},
|
|
})
|
|
var validationError *ValidationError
|
|
if !errors.As(got, &validationError) || validationError.Check != "workspace-files" {
|
|
t.Fatalf("converted error = %#v, want workspace-files validation identity", got)
|
|
}
|
|
if len(validationError.Findings) != 1 || validationError.Findings[0].Path != "nested/go.work.sum" {
|
|
t.Fatalf("converted findings = %#v, want nested workspace path", validationError.Findings)
|
|
}
|
|
}
|