github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/terminationworker/worker_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package terminationworker_test
     5  
     6  import (
     7  	"os"
     8  	"testing"
     9  
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/worker"
    14  	"github.com/juju/juju/worker/terminationworker"
    15  )
    16  
    17  func TestPackage(t *testing.T) {
    18  	gc.TestingT(t)
    19  }
    20  
    21  var _ = gc.Suite(&TerminationWorkerSuite{})
    22  
    23  type TerminationWorkerSuite struct{}
    24  
    25  func (s *TerminationWorkerSuite) TestStartStop(c *gc.C) {
    26  	w := terminationworker.NewWorker()
    27  	w.Kill()
    28  	err := w.Wait()
    29  	c.Assert(err, jc.ErrorIsNil)
    30  }
    31  
    32  func (s *TerminationWorkerSuite) TestSignal(c *gc.C) {
    33  	w := terminationworker.NewWorker()
    34  	proc, err := os.FindProcess(os.Getpid())
    35  	c.Assert(err, jc.ErrorIsNil)
    36  	defer proc.Release()
    37  	err = proc.Signal(terminationworker.TerminationSignal)
    38  	c.Assert(err, jc.ErrorIsNil)
    39  	err = w.Wait()
    40  	c.Assert(err, gc.Equals, worker.ErrTerminateAgent)
    41  }