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 "github.com/carlosframework/platform/internal/hostactors"
5 "github.com/carlosframework/platform/internal/hostbox"
6 "github.com/carlosframework/platform/internal/hostfloor"
7 "strings"
8 "testing"
9)
10
11func activationConsoleRoster() (hostactors.Roster, hostfloor.Enrollment) {
12 en := strings.Repeat("a", 32)
13 local := hostfloor.Enrollment{Box: "sophie", Enrollment: en, InstanceID: "i-sophie"}
14 return hostactors.Roster{HomeRegion: "ie", RequestLimitNS: int64(hostbox.RequestLimit), Publication: "published", Boxes: map[string]hostactors.Box{"sophie": {Enrollment: en, State: "active", Region: "ie", Cloud: hostactors.Cloud{Region: "eu-west-1", InstanceID: "i-sophie"}}}, Consoles: map[string]hostactors.Console{"dev-console": {InstanceID: "dev-console", Enrollment: strings.Repeat("b", 32), Namespaces: []string{"platform"}, Compute: &hostactors.ComputeBinding{Box: "sophie", Enrollment: en}}}}, local
15}
16func TestActivationConsoleSeparatesHostExecution(t *testing.T) {
17 r, local := activationConsoleRoster()
18 for _, runtime := range []bool{false, true} {
19 got, err := activationConsoleEnvironment(r, local, []byte("CARLOS_REGION=\n"), "dev-console", runtime)
20 if err != nil || !strings.Contains(string(got), "CARLOS_CONSOLE_ID=dev-console\nCONSOLE_HOME_REGION=ie\n") {
21 t.Fatal(string(got), err)
22 }
23 if strings.Contains(string(got), "CARLOS_HOST_CLAIM=1\n") != runtime {
24 t.Fatal("wrong runtime flag", string(got))
25 }
26 }
27 for _, env := range []string{"CARLOS_HOST_CLAIM=1\n", "CARLOS_HOST_CLAIM=0\n", "CARLOS_REGION=ie\n", "malformed"} {
28 if _, err := activationConsoleEnvironment(r, local, []byte(env), "dev-console", true); err == nil {
29 t.Fatal("host execution accepted", env)
30 }
31 }
32 local.InstanceID = "i-leo"
33 if _, err := activationConsoleEnvironment(r, local, nil, "dev-console", true); err == nil {
34 t.Fatal("wrong local box accepted")
35 }
36}
37