34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package contracts
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidationResultRejectsInvalidFindings(t *testing.T) {
|
|
for _, result := range []ValidationResult{
|
|
{CorrectionGuidance: "Correct the response."},
|
|
{ReasonCode: "invalid"},
|
|
{ReasonCode: strings.Repeat("a", MaxValidationReasonCodeBytes+1), CorrectionGuidance: "Correct the response."},
|
|
{ReasonCode: " \t", CorrectionGuidance: "Correct the response."},
|
|
{ReasonCode: "invalid", CorrectionGuidance: string([]byte{0xff})},
|
|
{ReasonCode: "invalid", CorrectionGuidance: strings.Repeat("a", MaxValidationCorrectionGuidanceBytes+1)},
|
|
{Approved: true, Diagnostics: []ProducerDiagnostic{{}}},
|
|
} {
|
|
if err := ValidateValidationResult(result); err == nil {
|
|
t.Fatalf("invalid validation result accepted: %#v", result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidationResultAllowsAbsentOptionalCorrectionFields(t *testing.T) {
|
|
for _, result := range []ValidationResult{
|
|
{Approved: true},
|
|
{ReasonCode: "invalid-evidence", CorrectionGuidance: "Provide source-backed evidence."},
|
|
} {
|
|
if err := ValidateValidationResult(result); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|