38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package releasekit
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/ReleaseKit/internal/validation"
|
|
)
|
|
|
|
func TestSharedFileFailureKeepsPublicIdentityPathAndCause(t *testing.T) {
|
|
cause := errors.New("selected file is missing")
|
|
err := convertValidationError(&validation.Failure{
|
|
Check: validation.SharedFiles,
|
|
Findings: []validation.Finding{{
|
|
Path: "shared/NOTICE.md",
|
|
Message: "selected shared file is not present in the committed tree",
|
|
}},
|
|
Cause: cause,
|
|
})
|
|
var failure *ValidationError
|
|
if !errors.As(err, &failure) {
|
|
t.Fatalf("converted error = %T, want *ValidationError", err)
|
|
}
|
|
if failure.Check != ValidationCheck("shared-files") {
|
|
t.Fatalf("validation check = %q, want shared-files", failure.Check)
|
|
}
|
|
if len(failure.Findings) != 1 || failure.Findings[0].Path != "shared/NOTICE.md" {
|
|
t.Fatalf("validation findings = %#v, want selected shared path", failure.Findings)
|
|
}
|
|
if !errors.Is(err, cause) {
|
|
t.Fatalf("converted error %v does not preserve its cause", err)
|
|
}
|
|
if !strings.Contains(err.Error(), "shared-files") || !strings.Contains(err.Error(), "shared/NOTICE.md") {
|
|
t.Fatalf("validation presentation = %q, want check and path", err)
|
|
}
|
|
}
|