carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "testing"
5
6 "github.com/carlosframework/platform/internal/hostbox"
7 "github.com/carlosframework/platform/internal/hostguard"
8 "github.com/carlosframework/platform/internal/instancectl"
9)
10
11func TestPlan14RetiredExecutionClosure(t *testing.T) {
12 for _, mode := range []string{"retired", "live", "foreign host", "foreign stamp", "barrier", "open writers", "unsettled unit", "foreign unit", "unfinished role", "bad completion"} {
13 t.Run(mode, func(t *testing.T) {
14 target := hostguard.FenceTarget{Host: "shop.example", Incarnation: "inc", Stamp: 3, Session: 4, Box: "box", Enrollment: "en", BootID: "boot", ControllerID: "controller"}
15 view := hostguard.FenceView{Host: target.Host, Retired: []hostguard.Captured{{Incarnation: target.Incarnation, Stamp: target.Stamp}}}
16 launch := hostbox.LaunchInventory{Target: target, WritersClosed: true, Reservations: []hostbox.LaunchReservation{{Target: target, State: hostbox.UnitSettled, Group: hostbox.LaunchGroup{RelativePath: instancectl.ClaimUnitControlGroup(target.Host)}}}}
17 switch mode {
18 case "live":
19 view.Retired = nil
20 case "foreign host":
21 view.Host = "other.example"
22 case "foreign stamp":
23 view.Retired[0].Stamp++
24 case "barrier":
25 view.Barrier = &target
26 case "open writers":
27 launch.WritersClosed = false
28 case "unsettled unit":
29 launch.Reservations[0].State = hostbox.UnitStarted
30 case "foreign unit":
31 launch.Reservations[0].Target.Session++
32 case "unfinished role":
33 launch.Reservations[0].State = "started"
34 case "bad completion":
35 launch.Completed.Count = 1
36 }
37 done, err := retiredExecutionLaunch(view, launch)
38 if mode == "retired" {
39 if !done || err != nil {
40 t.Fatalf("retired closure: %v %v", done, err)
41 }
42 } else if mode == "live" || mode == "foreign stamp" {
43 if done || err != nil {
44 t.Fatalf("live closure bypassed: %v %v", done, err)
45 }
46 } else if err == nil {
47 t.Fatal("unproven closure accepted")
48 }
49 })
50 }
51}
52