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

     1  package commandparser_test
     2  
     3  import (
     4  	"github.com/cloudfoundry-incubator/stembuild/commandparser"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	"os"
     8  	"path/filepath"
     9  )
    10  
    11  var _ = Describe("ConstructValidator", func() {
    12  
    13  	var (
    14  		c commandparser.ConstructValidator
    15  	)
    16  	BeforeEach(func() {
    17  		c = commandparser.ConstructValidator{}
    18  	})
    19  
    20  	Describe("PopulatedArgs", func() {
    21  		It("should return true if all arguments are present", func() {
    22  			nonEmptyArgs := c.PopulatedArgs("version", "ip", "username", "password")
    23  			Expect(nonEmptyArgs).To(BeTrue())
    24  		})
    25  
    26  		It("should return false if stemcellVersion argument is empty", func() {
    27  			nonEmptyArgs := c.PopulatedArgs("", "ip", "username", "password")
    28  			Expect(nonEmptyArgs).To(BeFalse())
    29  		})
    30  
    31  		It("should return false if winrmIp argument is empty", func() {
    32  			nonEmptyArgs := c.PopulatedArgs("version", "", "username", "password")
    33  			Expect(nonEmptyArgs).To(BeFalse())
    34  		})
    35  
    36  		It("should return false if username argument is empty", func() {
    37  			nonEmptyArgs := c.PopulatedArgs("version", "ip", "", "password")
    38  			Expect(nonEmptyArgs).To(BeFalse())
    39  		})
    40  
    41  		It("should return false if password argument is empty", func() {
    42  			nonEmptyArgs := c.PopulatedArgs("version", "ip", "username", "")
    43  			Expect(nonEmptyArgs).To(BeFalse())
    44  		})
    45  	})
    46  
    47  	Describe("LGPOInDirectory", func() {
    48  		wd, _ := os.Getwd()
    49  		LGPOPath := filepath.Join(wd, "LGPO.zip")
    50  
    51  		It("should return true if LGPO exists in the directory", func() {
    52  			file, err := os.Create(LGPOPath)
    53  			Expect(err).ToNot(HaveOccurred())
    54  			_, err = os.Stat(LGPOPath)
    55  			Expect(err).ToNot(HaveOccurred())
    56  			file.Close()
    57  
    58  			result := c.LGPOInDirectory()
    59  
    60  			Expect(result).To(BeTrue())
    61  
    62  			err = os.Remove(LGPOPath)
    63  			Expect(err).ToNot(HaveOccurred())
    64  		})
    65  
    66  		It("should return false if LGPO doesn't exist in the directory", func() {
    67  			result := c.LGPOInDirectory()
    68  
    69  			Expect(result).To(BeFalse())
    70  		})
    71  	})
    72  })