60 lines
2.3 KiB
Go
60 lines
2.3 KiB
Go
package assign
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// 1297/B5: given the controller sent F to a node while the canary is not yet healthy on F, the difference names rule 3.
|
|
func TestADifferenceExplainedByTheCanary(t *testing.T) {
|
|
m, n := ready()
|
|
n.Haves["ace"]["mail"] = delivery.Have{FP: fOld, Phase: delivery.PhaseRunning, Health: delivery.HealthOK}
|
|
out := Wants(m, n, wantedOld(), nil)
|
|
want := delivery.Want{FP: fOld, Newest: fNew, Rule: delivery.RuleCanary}
|
|
d, ok := Compare(&want, Sent{Sends: true, Build: "b-9", FP: fNew}, fNew, out.Rules["g14"])
|
|
if !ok || d.Rule != delivery.RuleCanary || d.Unexplained || d.Want != fOld || d.Sent != fNew {
|
|
t.Fatalf("difference = %+v, %v; want rule 3", d, ok)
|
|
}
|
|
if _, err := delivery.EncodeDifference(d); err != nil {
|
|
t.Errorf("the difference cannot be written: %v", err)
|
|
}
|
|
}
|
|
|
|
// 1297/B5: a want equal to what is sent is no difference; nothing sent and no want is none; every other is written
|
|
// unexplained, with words, and is writable.
|
|
func TestCompare(t *testing.T) {
|
|
w := delivery.Want{FP: fNew}
|
|
if _, ok := Compare(&w, Sent{Sends: true, Build: "b", FP: fNew}, fNew, Holding{}); ok {
|
|
t.Errorf("an equal want and send is a difference")
|
|
}
|
|
if _, ok := Compare(nil, Sent{}, fNew, Holding{}); ok {
|
|
t.Errorf("no want and nothing sent is a difference")
|
|
}
|
|
removed := delivery.Want{Removed: true}
|
|
if _, ok := Compare(&removed, Sent{}, fNew, Holding{}); ok {
|
|
t.Errorf("a removed want and nothing sent is a difference")
|
|
}
|
|
old := delivery.Want{FP: fOld}
|
|
for name, c := range map[string]struct {
|
|
want *delivery.Want
|
|
sent Sent
|
|
}{
|
|
"sends an older one": {&w, Sent{Sends: true, Build: "b", FP: fOld}},
|
|
"names no fingerprint": {&w, Sent{Sends: true, Build: "b"}},
|
|
"sends a removed module": {&removed, Sent{Sends: true, Build: "b", FP: fNew}},
|
|
"sends nothing": {&w, Sent{}},
|
|
"no want": {nil, Sent{Sends: true, Build: "b", FP: fNew}},
|
|
"no rule holds it back": {&old, Sent{Sends: true, Build: "b", FP: fNew}},
|
|
} {
|
|
d, ok := Compare(c.want, c.sent, fNew, Holding{})
|
|
if !ok || !d.Unexplained || d.Words == "" {
|
|
t.Errorf("%s: difference = %+v, %v; want it unexplained, with words", name, d, ok)
|
|
continue
|
|
}
|
|
if _, err := delivery.EncodeDifference(d); err != nil {
|
|
t.Errorf("%s: the difference cannot be written: %v", name, err)
|
|
}
|
|
}
|
|
}
|