src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/daemon/server_unix_test.go (about)

     1  //go:build unix
     2  
     3  package daemon
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  	"testing"
     9  )
    10  
    11  func TestProgram_QuitsOnSystemSignal_SIGINT(t *testing.T) {
    12  	testProgram_QuitsOnSystemSignal(t, syscall.SIGINT)
    13  }
    14  
    15  func TestProgram_QuitsOnSystemSignal_SIGTERM(t *testing.T) {
    16  	testProgram_QuitsOnSystemSignal(t, syscall.SIGTERM)
    17  }
    18  
    19  func testProgram_QuitsOnSystemSignal(t *testing.T, sig os.Signal) {
    20  	t.Helper()
    21  	setup(t)
    22  	startServerOpts(t, cli("sock", "db"), ServeOpts{Signals: nil})
    23  	p, err := os.FindProcess(os.Getpid())
    24  	if err != nil {
    25  		t.Fatalf("FindProcess: %v", err)
    26  	}
    27  	p.Signal(sig)
    28  	// startServerOpts will wait for server to terminate at cleanup
    29  }