package web
import "testing"
// A pair of tips is drawn once: a second build returns the same view,
// and each caller's copy is its own to fill in.
func TestAConflictViewIsBuiltOncePerPairOfTips(t *testing.T) {
rep := conflictsReport{Branch: "b", Target: "trunk", BranchTip: "aaaa1111", TargetTip: "bbbb2222",
Verdict: "conflict"}
first := buildMeld(rep, "/r/x")
first.ResolveURL, first.Into = "/r/x/merge/resolve", append(first.Into, meldInto{Value: "onto", Name: "trunk"})
second := buildMeld(rep, "/r/x")
if second.ResolveURL != "" || len(second.Into) != 0 {
t.Errorf("FAIL: one caller's changes reached the next: %+v", second)
}
if second.BranchTip != "aaaa1111" || second.Branch != "b" {
t.Errorf("FAIL: the cached view lost its pair: %+v", second)
}
melds.Lock()
n := melds.order.Len()
melds.Unlock()
for i := 0; i < meldCacheSize+5; i++ {
buildMeld(conflictsReport{Branch: "b", Target: "trunk", BranchTip: string(rune('a'+i)) + "tip", TargetTip: "t"}, "/r/x")
}
melds.Lock()
if melds.order.Len() > meldCacheSize || n == 0 {
t.Errorf("FAIL: the cache holds %d views (bound %d, %d before)", melds.order.Len(), meldCacheSize, n)
}
melds.Unlock()
}