github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/helpers/buildpack.go (about) 1 package helpers 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 // MakeBuildpackArchive makes a simple buildpack zip for a given stack. 15 func MakeBuildpackArchive(stackName string) string { 16 archiveFile, err := ioutil.TempFile("", "buildpack-archive-file-") 17 Expect(err).ToNot(HaveOccurred()) 18 err = archiveFile.Close() 19 Expect(err).ToNot(HaveOccurred()) 20 err = os.RemoveAll(archiveFile.Name()) 21 Expect(err).ToNot(HaveOccurred()) 22 23 archiveName := archiveFile.Name() + ".zip" 24 25 dir, err := ioutil.TempDir("", "buildpack-dir-") 26 Expect(err).ToNot(HaveOccurred()) 27 defer os.RemoveAll(dir) 28 29 manifest := filepath.Join(dir, "manifest.yml") 30 err = ioutil.WriteFile(manifest, []byte(fmt.Sprintf("stack: %s", stackName)), 0666) 31 Expect(err).ToNot(HaveOccurred()) 32 33 err = Zipit(dir, archiveName, "") 34 Expect(err).ToNot(HaveOccurred()) 35 36 return archiveName 37 } 38 39 // BuildpackWithStack makes a simple buildpack for the given stack (using 40 // MakeBuildpackArchive) and yields it to the given function, removing the zip 41 // at the end. 42 func BuildpackWithStack(f func(buildpackArchive string), stackName string) { 43 buildpackZip := MakeBuildpackArchive(stackName) 44 defer os.Remove(buildpackZip) 45 46 f(buildpackZip) 47 } 48 49 // BuildpackWithoutStack makes a simple buildpack without a stack (using 50 // MakeBuildpackArchive) and yields it to the given function, removing the zip 51 // at the end. 52 func BuildpackWithoutStack(f func(buildpackArchive string)) { 53 BuildpackWithStack(f, "") 54 } 55 56 // SetupBuildpackWithStack makes and uploads a buildpack for the given stack. 57 func SetupBuildpackWithStack(buildpackName, stack string) { 58 BuildpackWithStack(func(buildpackPath string) { 59 session := CF("create-buildpack", buildpackName, buildpackPath, "99") 60 Eventually(session).Should(Say("OK")) 61 Eventually(session).Should(Say("OK")) 62 Eventually(session).Should(Exit(0)) 63 }, stack) 64 } 65 66 // SetupBuildpackWithoutStack makes and uploads a buildpack without a stack. 67 func SetupBuildpackWithoutStack(buildpackName string) { 68 SetupBuildpackWithStack(buildpackName, "") 69 } 70 71 // BuildpackFields represents a buildpack, displayed in the 'cf buildpacks' 72 // command. 73 type BuildpackFields struct { 74 Position string 75 Name string 76 Enabled string 77 Locked string 78 Filename string 79 Stack string 80 } 81 82 // DeleteBuildpackIfOnOldCCAPI deletes the buildpack if the CC API targeted 83 // by the current test run is <= 2.80.0. Before this version, some entities 84 // would receive and invalid next_url in paginated requests. Since our test run 85 // now generally creates more than 50 buildpacks, we need to delete test buildpacks 86 // after use if we are targeting and older CC API. 87 // see https://github.com/cloudfoundry/capi-release/releases/tag/1.45.0 88 func DeleteBuildpackIfOnOldCCAPI(buildpackName string) { 89 minVersion := "2.99.0" 90 if !IsVersionMet(minVersion) { 91 deleteSessions := CF("delete-buildpack", buildpackName, "-f") 92 Eventually(deleteSessions).Should(Exit()) 93 } 94 }