carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package host
4
5import (
6 "errors"
7 "testing"
8
9 "github.com/carlosframework/platform/internal/hostclaim"
10 "github.com/carlosframework/platform/internal/hostguard"
11)
12
13func TestPlan14ExecutionPreinstallationSourceGap(t *testing.T) {
14 t.Parallel()
15 for _, phase := range []string{hostclaim.PhaseStarting, hostclaim.PhaseReleasing, hostclaim.PhasePinning} {
16 t.Run(phase, func(t *testing.T) {
17 b := newParticipationBox(t)
18 o := b.update(func(c *hostclaim.Claim) error {
19 c.Op.Phase = phase
20 c.Op.Exec = "src"
21 if phase == hostclaim.PhasePinning {
22 c.Op.Exec = "none"
23 }
24 return nil
25 })
26 root := b.guard
27 root.Root = hostguard.NewRootAuthority(&rollbackDisk{dir: t.TempDir()})
28 if _, err := root.Capture(o.Host); !errors.Is(err, hostguard.ErrNoRecord) {
29 t.Fatalf("target unexpectedly has a root installation: %v", err)
30 }
31 if err := rootFirstInstallation(o.Claim, b.actor); err == nil {
32 t.Fatal("first registration admitted before installation")
33 }
34 effects := RelocationEffects{Participation: b.p.Acknowledged}
35 ack, err := effects.Acknowledge(t.Context(), o)
36 if err != nil {
37 t.Fatal("existing participation cannot acknowledge before installation:", err)
38 }
39 if ack.Op != o.Claim.Op.ID || ack.Enrollment != b.actor.Enrollment || ack.LeaseETag == "" {
40 t.Fatalf("missing execution acknowledgement: %+v", ack)
41 }
42 if _, err := root.Capture(o.Host); !errors.Is(err, hostguard.ErrNoRecord) {
43 t.Fatalf("participation fabricated a root installation: %v", err)
44 }
45 })
46 }
47}
48