All checks were successful
ci/woodpecker/tag/release Pipeline was successful
39 lines
1.4 KiB
Go
39 lines
1.4 KiB
Go
package proposal_generation
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/outcomes"
|
|
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/structuredoutput"
|
|
)
|
|
|
|
func TestDecodeRepairResponse(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, content string
|
|
valid bool
|
|
}{
|
|
{"revision with deletion", `{"proposal_ref":2,"decision":{"action":"revise","correction":{"id":1,"original_text":" ","corrected_text":""}}}`, true},
|
|
{"withdrawal", `{"proposal_ref":2,"decision":{"action":"withdraw","correction":null}}`, true},
|
|
{"wrong reference", `{"proposal_ref":1e0,"decision":{"action":"withdraw","correction":null}}`, false},
|
|
{"missing revision", `{"proposal_ref":2,"decision":{"action":"revise","correction":null}}`, false},
|
|
{"withdrawal with revision", `{"proposal_ref":2,"decision":{"action":"withdraw","correction":{"id":1}}}`, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
response, err := DecodeRepairResponse([]byte(tc.content), 2)
|
|
if tc.valid && err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !tc.valid {
|
|
if response.ProposalRef == 0 || response.Decision.Action == "" {
|
|
t.Fatalf("missing decoded evidence: %+v", response)
|
|
}
|
|
var failure *structuredoutput.Failure
|
|
if !errors.As(err, &failure) || failure.Reason != outcomes.ReasonInvalidOutput || failure.Class != structuredoutput.FailureRecoverable {
|
|
t.Fatalf("failure = %v", err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|