github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/package_stemcell/ovftool/ovftool_portable_test.go (about)

     1  //go:build !darwin && !windows
     2  // +build !darwin,!windows
     3  
     4  package ovftool_test
     5  
     6  import (
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  
    10  	"io/ioutil"
    11  	"os"
    12  	"path/filepath"
    13  
    14  	"github.com/cloudfoundry-incubator/stembuild/package_stemcell/ovftool"
    15  )
    16  
    17  var _ = Describe("ovftool", func() {
    18  
    19  	var oldPath string
    20  
    21  	BeforeEach(func() {
    22  		oldPath = os.Getenv("PATH")
    23  		os.Unsetenv("PATH")
    24  	})
    25  
    26  	AfterEach(func() {
    27  		os.Setenv("PATH", oldPath)
    28  	})
    29  
    30  	It("when ovftool is on the PATH, its path is returned", func() {
    31  		tmpDir, err := ioutil.TempDir(os.TempDir(), "ovftmp")
    32  		Expect(err).ToNot(HaveOccurred())
    33  		err = ioutil.WriteFile(filepath.Join(tmpDir, "ovftool"), []byte{}, 0700)
    34  		Expect(err).ToNot(HaveOccurred())
    35  		os.Setenv("PATH", tmpDir)
    36  
    37  		ovfPath, err := ovftool.Ovftool([]string{})
    38  		os.RemoveAll(tmpDir)
    39  
    40  		Expect(err).ToNot(HaveOccurred())
    41  		Expect(ovfPath).To(Equal(filepath.Join(tmpDir, "ovftool")))
    42  	})
    43  
    44  	It("fails when ovftool is not installed in the PATH", func() {
    45  		_, err := ovftool.Ovftool([]string{})
    46  		Expect(err).To(HaveOccurred())
    47  	})
    48  })