feat: add host actions, lifecycle hooks and operational tools
This commit is contained in:
1 parent
8d4915543e
commit
e5bde9c61f
32 files changed
+2083
-64
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestExitAndTimeout(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
r := Run(context.Background(), []string{"sh", "-c", "printf result; exit 7"}, Options{Stdout: &out, Stderr: io.Discard})
|
||||
if !r.Started || r.Code != 7 || out.String() != "result" {
|
||||
t.Fatalf("%+v %q", r, out.String())
|
||||
}
|
||||
start := time.Now()
|
||||
r = Run(context.Background(), []string{"sh", "-c", "trap '' TERM; sleep 30 & wait"}, Options{Stdout: io.Discard, Stderr: io.Discard, Timeout: 50 * time.Millisecond})
|
||||
if r.Code != 124 || time.Since(start) > 4*time.Second {
|
||||
t.Fatalf("timeout: %+v", r)
|
||||
}
|
||||
}
|
||||
func TestCancellationAndNoStart(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
r := Run(ctx, []string{"sh", "-c", "exit 0"}, Options{Stderr: io.Discard})
|
||||
if r.Started || r.Code != 130 {
|
||||
t.Fatalf("%+v", r)
|
||||
}
|
||||
var errOut bytes.Buffer
|
||||
r = Run(context.Background(), []string{"/no/such/netssh-test-executable"}, Options{Stderr: &errOut})
|
||||
if r.Started || r.Code == 0 || !strings.Contains(errOut.String(), "no such") {
|
||||
t.Fatalf("%+v %s", r, errOut.String())
|
||||
}
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
time.AfterFunc(50*time.Millisecond, cancel)
|
||||
r = Run(ctx, []string{"sh", "-c", "sleep 30"}, Options{Stdout: io.Discard, Stderr: io.Discard})
|
||||
if r.Code != 130 {
|
||||
t.Fatalf("%+v", r)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user