package judge import ( "strings" "testing" "git.novox.be/novox/mesh-sdk/go/delivery" ) // 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 placement test with FitAnswer, novox/hq ADR 0593 ยง7). func TestFitAnswer(t *testing.T) { long := strings.Repeat("x", delivery.MaxBody) big := CandidateAnswer{Proposal: "p-x1", Revision: 1, Verdict: delivery.CandidateDiffers, 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 != delivery.CandidateDiffers || !strings.Contains(fitted.Note, "cut") || big.Differs[0].Bodies[0].Composed == "" { t.Errorf("fitted as %+v", fitted) } }