| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/cgroup" |
| 7 | "github.com/carlosframework/platform/internal/hostguard" |
| 8 | ) |
| 9 | |
| 10 | // Final review round 1, merge item 8: internal/cgroup's retaining setup |
| 11 | // leaves claim containment groups alone (it seeds and sweeps around them, |
| 12 | // flag off included), and it knows them only by their name. The name's |
| 13 | // format has one definition, in internal/cgroup, and every name this |
| 14 | // package makes must read as one there, both as the containment's host name |
| 15 | // and as its exec cgroup's directory name. A plain host never does. |
| 16 | func TestClaimContainmentNamesAreRecognisedByTheCgroupPackage(t *testing.T) { |
| 17 | for _, target := range []hostguard.FenceTarget{ |
| 18 | {}, |
| 19 | {Host: "a.example.com", Incarnation: "inc-1", Stamp: 3, Session: 9, Box: "box-1", Enrollment: "e", BootID: "boot", ControllerID: "ctl"}, |
| 20 | {Host: "claim-x.local", Incarnation: "inc-2", Stamp: 1, Session: 1, Box: "box-2"}, |
| 21 | } { |
| 22 | name := claimContainmentName(target) |
| 23 | if !cgroup.IsClaimContainment(name) { |
| 24 | t.Fatalf("cgroup.IsClaimContainment(%q) = false for a claim containment name", name) |
| 25 | } |
| 26 | if !cgroup.IsClaimContainment(cgroup.ExecName(name)) { |
| 27 | t.Fatalf("cgroup.IsClaimContainment(%q) = false for its exec cgroup", cgroup.ExecName(name)) |
| 28 | } |
| 29 | } |
| 30 | for _, plain := range []string{"a.example.com", cgroup.ExecName("a.example.com"), "claim-a.example.com", "x.local"} { |
| 31 | if cgroup.IsClaimContainment(plain) { |
| 32 | t.Fatalf("cgroup.IsClaimContainment(%q) = true for a name that is not a claim containment's", plain) |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |