github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/requirements/buildpack_test.go (about)

     1  package requirements_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/api/apifakes"
     5  	"code.cloudfoundry.org/cli/cf/models"
     6  	. "code.cloudfoundry.org/cli/cf/requirements"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("BuildpackRequirement", func() {
    12  	It("succeeds when a buildpack with the given name exists", func() {
    13  		buildpack := models.Buildpack{Name: "my-buildpack"}
    14  		buildpackRepo := &apifakes.OldFakeBuildpackRepository{FindByNameBuildpack: buildpack}
    15  
    16  		buildpackReq := NewBuildpackRequirement("my-buildpack", "", buildpackRepo)
    17  
    18  		Expect(buildpackReq.Execute()).NotTo(HaveOccurred())
    19  		Expect(buildpackRepo.FindByNameName).To(Equal("my-buildpack"))
    20  		Expect(buildpackReq.GetBuildpack()).To(Equal(buildpack))
    21  	})
    22  
    23  	It("fails when the buildpack cannot be found", func() {
    24  		buildpackRepo := &apifakes.OldFakeBuildpackRepository{FindByNameNotFound: true}
    25  
    26  		err := NewBuildpackRequirement("foo", "", buildpackRepo).Execute()
    27  		Expect(err).To(HaveOccurred())
    28  		Expect(err.Error()).To(ContainSubstring("Buildpack foo not found"))
    29  	})
    30  
    31  	It("fails when more than one buildpack is found with the same name and no stack is specified", func() {
    32  		buildpackRepo := &apifakes.OldFakeBuildpackRepository{FindByNameAmbiguous: true}
    33  
    34  		err := NewBuildpackRequirement("foo", "", buildpackRepo).Execute()
    35  		Expect(err).To(HaveOccurred())
    36  		Expect(err.Error()).To(ContainSubstring("Multiple buildpacks named foo found"))
    37  	})
    38  
    39  	It("finds buildpacks by stack if specified, in addition to name", func() {
    40  		buildpack := models.Buildpack{Name: "my-buildpack", Stack: "my-stack"}
    41  		buildpackRepo := &apifakes.OldFakeBuildpackRepository{FindByNameAndStackBuildpack: buildpack}
    42  
    43  		buildpackReq := NewBuildpackRequirement("my-buildpack", "my-stack", buildpackRepo)
    44  
    45  		Expect(buildpackReq.Execute()).NotTo(HaveOccurred())
    46  		Expect(buildpackRepo.FindByNameAndStackName).To(Equal("my-buildpack"))
    47  		Expect(buildpackRepo.FindByNameAndStackStack).To(Equal("my-stack"))
    48  		Expect(buildpackReq.GetBuildpack()).To(Equal(buildpack))
    49  	})
    50  })