Gitfed
bastien-mrq/sssh / internal / process / process_test.go
package process

import (
	"context"
	"errors"
	"os/exec"
	"testing"
	"time"
)

func TestCancellation(t *testing.T) {
	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
	defer cancel()
	start := time.Now()
	err := Run(ctx, exec.Command("sh", "-c", "sleep 60 & wait"))
	if !errors.Is(err, context.DeadlineExceeded) {
		t.Fatalf("cancel: %v", err)
	}
	if time.Since(start) > 4*time.Second {
		t.Fatal("shell did not stop promptly")
	}
}