53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// The roles a copy of this test binary plays in TestAVerbRunsWhileItsBuildIsMovedOrDeleted.
|
|
const selfExecRole = "MESH_CONTROLLER_SELFEXEC_ROLE"
|
|
|
|
// TestSelfExecServer is a controller standing in, when run as one: it waits until its build has been
|
|
// moved, then runs a verb as the seat runs one, and prints what came of it as JSON.
|
|
|
|
// TestSelfExecVerb is the verb, when run as one.
|
|
func TestSelfExecVerb(t *testing.T) {
|
|
if os.Getenv(selfExecRole) != "verb" {
|
|
t.Skip("run by TestSelfExecServer")
|
|
}
|
|
fmt.Println("the verb ran")
|
|
}
|
|
|
|
// **A verb runs while the build it was started from is moved where its user may not go, or deleted**
|
|
// (novox/hq issue 289). The node-engine's witness moves a running controller's build into a directory
|
|
// only it may enter as it places the next, and deletes it once the next is proved; the controller
|
|
// still serving in between ran its verbs from the path and answered "permission denied".
|
|
//
|
|
// A copy of this test binary is the controller: started from one place, moved into a directory closed
|
|
// to everyone (or deleted), and only then asked to run a verb.
|
|
|
|
// A verb the controller cannot start from its own build is refused as a handover — marked so its
|
|
// caller asks again — never a permission error; and so is one arriving once the controller is stopping.
|
|
|
|
func copyFile(t *testing.T, from, to string) {
|
|
t.Helper()
|
|
in, err := os.Open(from)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer in.Close()
|
|
out, err := os.OpenFile(to, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o755)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := io.Copy(out, in); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := out.Close(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|