carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package hostbox
2
3import (
4 "context"
5 "errors"
6 "github.com/carlosframework/platform/internal/hostwrite"
7 "testing"
8)
9
10func TestStartupFlagOnceAndInert(t *testing.T) {
11 for _, value := range []string{"", " ", "0", "1"} {
12 reads, calls := 0, 0
13 cfg, err := Startup(context.Background(), func(name string) string {
14 reads++
15 if name != "CARLOS_HOST_CLAIM" {
16 t.Fatal(name)
17 }
18 return value
19 }, func(context.Context) (hostwrite.Selector, error) { calls++; return nil, hostwrite.ErrUnavailable })
20 on := value == "0" || value == "1"
21 if reads != 1 || cfg.Enabled != on || (calls == 1) != on || (err != nil) != on {
22 t.Fatalf("%q: %+v %v %d %d", value, cfg, err, reads, calls)
23 }
24 }
25}
26
27type refuseRoster struct{}
28
29func (refuseRoster) Actor(context.Context, string) (Actor, error) {
30 return Actor{}, errors.New("unverified roster")
31}
32func TestIdentityHasNoRegionOnlyFallback(t *testing.T) {
33 if _, err := (IdentityProvider{Box: "box", Region: "ie", Roster: refuseRoster{}}).Verify(context.Background()); err == nil {
34 t.Fatal("identity without boxid evidence")
35 }
36}
37