package delivery import "testing" // 1952 S7 (ADR 0564 clause 13 (a), (c) and Limits 12; ADR 0540 ยง7): one derivation of whether a module is being // delivered on a node, read by the view (moving, settled, stuck, as its motionOf said them) and by the condition keeper // (delivering, failed, ended). Wants and haves as the assigner and the node-engine write them (assigner.go Want, // delivery.go Have; agent.go writes a refusal as phase failed at the prior fingerprint). func TestMotionOf(t *testing.T) { want := Want{V: Version, FP: "fp-new", Composed: "sha256:new"} at := func(fp, composed string, phase Phase, health Health, detail string) Have { return Have{V: Version, FP: fp, Composed: composed, Phase: phase, Health: health, Detail: detail} } for _, c := range []struct { name string w Want wanted bool h Have has bool stuck string state string outcome string delivering bool failed bool ended bool }{ {name: "no want", h: at("fp-old", "", PhaseRunning, HealthOK, ""), has: true}, {name: "a removed want", w: Want{V: Version, Removed: true}, wanted: true}, {name: "a want no node has yet", w: want, wanted: true, state: MotionMoving, delivering: true}, {name: "the old fingerprint still runs", w: want, wanted: true, h: at("fp-old", "sha256:old", PhaseRunning, HealthOK, ""), has: true, state: MotionMoving, delivering: true}, {name: "applying the wanted fingerprint", w: want, wanted: true, h: at("fp-new", "sha256:new", PhaseApplying, HealthUnknown, ""), has: true, state: MotionMoving, delivering: true}, {name: "checking at the want: no longer delivering, not yet settled", w: want, wanted: true, h: at("fp-new", "sha256:new", PhaseChecking, HealthUnknown, ""), has: true, state: MotionMoving}, {name: "running healthy at the want", w: want, wanted: true, h: at("fp-new", "sha256:new", PhaseRunning, HealthOK, ""), has: true, state: MotionSettled, outcome: OutcomeRunning, ended: true}, {name: "running healthy at another composition", w: want, wanted: true, h: at("fp-new", "sha256:other", PhaseRunning, HealthOK, ""), has: true, state: MotionMoving}, {name: "unhealthy at the want", w: want, wanted: true, h: at("fp-new", "sha256:new", PhaseRunning, HealthFailed, "exit 1"), has: true, state: MotionStuck, outcome: OutcomeFailed, failed: true, ended: true}, {name: "its apply failed at the want", w: want, wanted: true, h: at("fp-new", "sha256:new", PhaseFailed, HealthUnknown, "no image"), has: true, state: MotionStuck, outcome: OutcomeFailed, failed: true, ended: true}, {name: "refused, the prior fingerprint kept", w: want, wanted: true, h: at("fp-old", "sha256:old", PhaseFailed, HealthOK, "not composed: no grant"), has: true, state: MotionMoving, delivering: true, failed: true, ended: true}, {name: "held on the node", w: want, wanted: true, h: at("fp-old", "sha256:old", PhaseHeld, HealthOK, "held by a person"), has: true, state: MotionStuck, outcome: OutcomeStopped, delivering: true}, {name: "the watchman says it stopped moving", w: want, wanted: true, h: at("fp-old", "sha256:old", PhaseRunning, HealthOK, ""), has: true, stuck: "ace to apply fp-new", state: MotionStuck, outcome: OutcomeStopped, delivering: true}, } { m := MotionOf(c.w, c.wanted, c.h, c.has, c.stuck, c.stuck != "") if m.State != c.state || m.Outcome != c.outcome || m.Delivering != c.delivering || m.Failed != c.failed || m.Ended() != c.ended { t.Errorf("%s: %+v (ended %v), want state %q outcome %q delivering %v failed %v ended %v", c.name, m, m.Ended(), c.state, c.outcome, c.delivering, c.failed, c.ended) } } }