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 "os"
7 "testing"
8
9 "github.com/carlosframework/platform/internal/activator"
10 "github.com/carlosframework/platform/internal/hostwrite"
11 "github.com/carlosframework/platform/internal/registry"
12 "github.com/carlosframework/platform/internal/release"
13)
14
15func TestPlan14ERecoveryOrdinaryPass(t *testing.T) {
16 if !plan14RootFixture(t) {
17 return
18 }
19 for _, shape := range []string{"unstamped", "derived", "exec", "named refusal"} {
20 t.Run(shape, func(t *testing.T) {
21 f := r2Fixture(t, "none")
22 f.rt.Unit = ""
23 f.rt.Backing = registry.BackingUnit
24 if shape == "derived" {
25 f.rt.Unit = activator.UnitName(f.rt.Host)
26 }
27 if shape == "exec" {
28 f.rt.Backing = "exec"
29 }
30 if err := f.e.root.reg.Delete(f.rt.Host); err != nil {
31 t.Fatal(err)
32 }
33 if err := f.e.root.reg.Upsert(f.rt); err != nil {
34 t.Fatal(err)
35 }
36 reads := 0
37 f.c.legacy = func() (bool, error) {
38 reads++
39 if shape != "named refusal" {
40 t.Fatal("ordinary pass read census")
41 }
42 return false, os.ErrPermission
43 }
44 if shape == "named refusal" {
45 named := f.rt
46 named.Host = "failed.example.com"
47 named.Unit = "failed.service"
48 if err := f.e.root.reg.Upsert(named); err != nil {
49 t.Fatal(err)
50 }
51 }
52 n := productionNamedUnitRecovery(f.e.store, f.pub, f.u.opt, hostwrite.Config{})
53 if err := f.pass(t, release.WithRootHistory(nil), n.passOption(f.e.root.reg, f.c, func(string) string { return "5s" })); err != nil {
54 t.Fatal(err)
55 }
56 f.wantLive(t, "v2")
57 if shape == "named refusal" && reads != 1 {
58 t.Fatalf("recovery census reads=%d, want one", reads)
59 }
60 })
61 }
62}
63