package host import ( "github.com/carlosframework/platform/internal/hostactors" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostfloor" "strings" "testing" ) func activationConsoleRoster() (hostactors.Roster, hostfloor.Enrollment) { en := strings.Repeat("a", 32) local := hostfloor.Enrollment{Box: "sophie", Enrollment: en, InstanceID: "i-sophie"} 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 } func TestActivationConsoleSeparatesHostExecution(t *testing.T) { r, local := activationConsoleRoster() for _, runtime := range []bool{false, true} { got, err := activationConsoleEnvironment(r, local, []byte("CARLOS_REGION=\n"), "dev-console", runtime) if err != nil || !strings.Contains(string(got), "CARLOS_CONSOLE_ID=dev-console\nCONSOLE_HOME_REGION=ie\n") { t.Fatal(string(got), err) } if strings.Contains(string(got), "CARLOS_HOST_CLAIM=1\n") != runtime { t.Fatal("wrong runtime flag", string(got)) } } for _, env := range []string{"CARLOS_HOST_CLAIM=1\n", "CARLOS_HOST_CLAIM=0\n", "CARLOS_REGION=ie\n", "malformed"} { if _, err := activationConsoleEnvironment(r, local, []byte(env), "dev-console", true); err == nil { t.Fatal("host execution accepted", env) } } local.InstanceID = "i-leo" if _, err := activationConsoleEnvironment(r, local, nil, "dev-console", true); err == nil { t.Fatal("wrong local box accepted") } }