package judge import ( nodeengine "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" "github.com/novox/mesh-host/internal/compositions" "strings" "testing" ) // An answer too large for the node's key is fitted: the texts go first, the verdict and the paths stay, and the answer // given is not changed (moved from mesh-sdk's assignment test with FitAnswer, novox/hq ADR 0593 ยง7). func TestFitAnswer(t *testing.T) { long := strings.Repeat("x", compositions.MaxBody) big := CandidateAnswer{Proposal: "p-x1", Revision: 1, Verdict: nodeengine.CandidateAnswerVerdictDiffers, Differs: []ModuleDiffers{{ Module: "nats", Why: "differs", Bodies: []ResourceBodies{{ID: "conf", Why: "changed", Paths: []string{"content.links.1", "content.password"}, Composed: long, Running: long}}}}} if same := FitAnswer(big, 1<<20); same.Note != "" || same.Differs[0].Bodies[0].Composed != long { t.Errorf("an answer within the bound was cut: %+v", same.Note) } fitted := FitAnswer(big, 4<<10) if len(fitted.Differs[0].Bodies[0].Composed) != 0 || len(fitted.Differs[0].Bodies[0].Paths) != 2 || fitted.Verdict != nodeengine.CandidateAnswerVerdictDiffers || !strings.Contains(fitted.Note, "cut") || big.Differs[0].Bodies[0].Composed == "" { t.Errorf("fitted as %+v", fitted) } }