github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/integration/interrupt_test.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package integration_test
     5  
     6  import (
     7  	"io/ioutil"
     8  	"os"
     9  	"path/filepath"
    10  	"time"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  
    15  	"github.com/cloudfoundry-incubator/stembuild/test/helpers"
    16  )
    17  
    18  var _ = Describe("Interrupts", func() {
    19  	Describe("catchInterruptSignal", func() {
    20  		It("cleans up on one interrupt", func() {
    21  			var err error
    22  			stembuildExecutable, err = helpers.BuildStembuild("1200.0.0")
    23  			Expect(err).ToNot(HaveOccurred())
    24  
    25  			inputVmdk := filepath.Join("..", "test", "data", "expected.vmdk")
    26  			tmpDir, err := ioutil.TempDir(os.TempDir(), "stembuild-interrupts")
    27  			Expect(err).ToNot(HaveOccurred())
    28  
    29  			session := helpers.Stembuild(stembuildExecutable, "package", "--vmdk", inputVmdk, "--outputDir", tmpDir)
    30  			time.Sleep(1 * time.Second)
    31  
    32  			err = session.Command.Process.Signal(os.Interrupt)
    33  			Expect(err).ToNot(HaveOccurred())
    34  			time.Sleep(1 * time.Second)
    35  
    36  			stdErr := session.Err.Contents()
    37  			Expect(string(stdErr)).To(ContainSubstring("received ("))
    38  		})
    39  
    40  		// Tried to create test to handle 2 interrupts in a row, but timing of processes makes it difficult
    41  		// to test
    42  	})
    43  })