github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/helpers/buildpack.go (about) 1 package helpers 2 3 import ( 4 "fmt" 5 . "github.com/onsi/gomega" 6 . "github.com/onsi/gomega/gbytes" 7 . "github.com/onsi/gomega/gexec" 8 "io/ioutil" 9 "os" 10 "path/filepath" 11 ) 12 13 func MakeBuildpackArchive(stackName string) string { 14 archiveFile, err := ioutil.TempFile("", "buildpack-archive-file-") 15 Expect(err).ToNot(HaveOccurred()) 16 err = archiveFile.Close() 17 Expect(err).ToNot(HaveOccurred()) 18 err = os.RemoveAll(archiveFile.Name()) 19 Expect(err).ToNot(HaveOccurred()) 20 21 archiveName := archiveFile.Name() + ".zip" 22 23 dir, err := ioutil.TempDir("", "buildpack-dir-") 24 Expect(err).ToNot(HaveOccurred()) 25 defer os.RemoveAll(dir) 26 27 manifest := filepath.Join(dir, "manifest.yml") 28 err = ioutil.WriteFile(manifest, []byte(fmt.Sprintf("stack: %s", stackName)), 0666) 29 Expect(err).ToNot(HaveOccurred()) 30 31 err = Zipit(dir, archiveName, "") 32 Expect(err).ToNot(HaveOccurred()) 33 34 return archiveName 35 } 36 37 func BuildpackWithStack(f func(buildpackArchive string), stackName string) { 38 buildpackZip := MakeBuildpackArchive(stackName) 39 defer os.Remove(buildpackZip) 40 41 f(buildpackZip) 42 } 43 44 type BuildpackFields struct { 45 Position string 46 Name string 47 Enabled string 48 Locked string 49 Filename string 50 Stack string 51 } 52 53 func BuildpackWithoutStack(f func(buildpackArchive string)) { 54 BuildpackWithStack(f, "") 55 } 56 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 func SetupBuildpackWithoutStack(buildpackName string) { 67 SetupBuildpackWithStack(buildpackName, "") 68 } 69 70 // DeleteBuildpackIfOnOldCCAPI deletes the buildpack if the CC API targeted 71 // by the current test run is <= 2.80.0. Before this version, some entities 72 // would receive and invalid next_url in paginated requests. Since our test run 73 // now generally creates more than 50 buildpacks, we need to delete test buildpacks 74 // after use if we are targeting and older CC API. 75 // see https://github.com/cloudfoundry/capi-release/releases/tag/1.45.0 76 func DeleteBuildpackIfOnOldCCAPI(buildpackName string) { 77 minVersion := "2.99.0" 78 if !IsVersionMet(minVersion) { 79 deleteSessions := CF("delete-buildpack", buildpackName, "-f") 80 Eventually(deleteSessions).Should(Exit()) 81 } 82 }