github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/pluginaction/install_windows_test.go (about)

     1  // +build windows
     2  
     3  package pluginaction_test
     4  
     5  import (
     6  	"io/ioutil"
     7  	"os"
     8  
     9  	. "code.cloudfoundry.org/cli/actor/pluginaction"
    10  	"code.cloudfoundry.org/cli/actor/pluginaction/pluginactionfakes"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("install actions", func() {
    16  	var (
    17  		actor         *Actor
    18  		fakeConfig    *pluginactionfakes.FakeConfig
    19  		tempPluginDir string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		fakeConfig = new(pluginactionfakes.FakeConfig)
    24  		var err error
    25  		tempPluginDir, err = ioutil.TempDir("", "")
    26  		Expect(err).ToNot(HaveOccurred())
    27  		actor = NewActor(fakeConfig, nil)
    28  	})
    29  
    30  	AfterEach(func() {
    31  		err := os.RemoveAll(tempPluginDir)
    32  		Expect(err).ToNot(HaveOccurred())
    33  	})
    34  
    35  	Describe("CreateExecutableCopy", func() {
    36  		When("the file exists", func() {
    37  			var pluginPath string
    38  
    39  			BeforeEach(func() {
    40  				tempFile, err := ioutil.TempFile("", "")
    41  				Expect(err).ToNot(HaveOccurred())
    42  
    43  				_, err = tempFile.WriteString("cthulhu")
    44  				Expect(err).ToNot(HaveOccurred())
    45  				err = tempFile.Close()
    46  				Expect(err).ToNot(HaveOccurred())
    47  
    48  				pluginPath = tempFile.Name()
    49  			})
    50  
    51  			AfterEach(func() {
    52  				err := os.Remove(pluginPath)
    53  				Expect(err).ToNot(HaveOccurred())
    54  			})
    55  
    56  			It("adds .exe to the end of the filename", func() {
    57  				copyPath, err := actor.CreateExecutableCopy(pluginPath, tempPluginDir)
    58  				Expect(err).ToNot(HaveOccurred())
    59  
    60  				Expect(copyPath).To(HaveSuffix(".exe"))
    61  			})
    62  		})
    63  	})
    64  })