package moves import ( "testing" "github.com/carlosframework/platform/internal/provision" ) // Final review M1: a stuck entry names the participant that stopped. The // target stops for an operator at its return (returning) and at its release // (releasing, StuckReleaseTargetFiles); every other stuck is the source's. func TestStuckNamesTheParticipantThatStopped(t *testing.T) { rec := func(state, target, source, reason string, dirty bool) provision.Record { return provision.Record{Host: "a.example.com", Move: &provision.MoveState{ID: "mv_abcdefghijklmnopqrstuvwxyz", Incarnation: "i", From: "ie", To: "uk", State: state, StuckReason: reason, Rollback: &provision.MoveRollback{ID: "rb_abcdefghijklmnopqrstuvwxyz", TargetPhase: target, SourcePhase: source, Dirty: dirty}}} } for _, c := range []struct { name string target, source string reason string dirty bool want string }{ {"the target's release", provision.RbTargetReleasing, provision.RbSourceWaiting, provision.StuckReleaseTargetFiles, false, "target"}, {"the target's return", provision.RbTargetReturning, provision.RbSourceWaiting, provision.StuckReturnTargetFiles, true, "target"}, {"the source's verification", provision.RbTargetCleaned, provision.RbSourceVerified, provision.StuckBaselineMismatch, false, "source"}, } { before := rec(provision.MoveRollingBack, c.target, c.source, "", c.dirty) after := rec(provision.MoveStuck, c.target, c.source, c.reason, c.dirty) e, ok := TransitionOf(before, after) if !ok || e.Event != "stuck" || e.Fields["role"] != c.want || e.Fields["reason"] != c.reason { t.Fatalf("%s: %+v %v, want stuck with role %s", c.name, e, ok, c.want) } } } // Final re-review 1, N1: DeclaredLost names a target loss only for a move on // the rollback path a target loss is declared on: a landing (which the // declaration rolls back) or a rollback. It fabricates none for any other // state, a committed move's above all. func TestDeclaredLostOnlyOnTheRollbackPath(t *testing.T) { for state, want := range map[string]bool{ provision.MoveLanding: true, provision.MoveRollingBack: true, provision.MoveCommitted: false, provision.MovePreparing: false, provision.MoveCutting: false, provision.MoveReverting: false, provision.MoveStuck: false, } { e, ok := DeclaredLost(&provision.MoveState{ID: "mv_abcdefghijklmnopqrstuvwxyz", Incarnation: "i", From: "ie", To: "uk", State: state}) if ok != want || ok && (e.Event != "declared_lost" || e.Identity != DeclaredLostIdentity) { t.Errorf("%s: %+v %v, want %v", state, e, ok, want) } } }