()
| 212 | }) |
| 213 | |
| 214 | func uploadBuildpackRequest() testnet.TestRequest { |
| 215 | return testnet.TestRequest{ |
| 216 | Method: "PUT", |
| 217 | Path: "/v2/buildpacks/my-cool-buildpack-guid/bits", |
| 218 | Response: testnet.TestResponse{ |
| 219 | Status: http.StatusCreated, |
| 220 | Body: `{ "metadata":{ "guid": "my-job-guid" } }`, |
| 221 | }, |
| 222 | Matcher: func(request *http.Request) { |
| 223 | err := request.ParseMultipartForm(4096) |
| 224 | defer request.MultipartForm.RemoveAll() |
| 225 | Expect(err).NotTo(HaveOccurred()) |
| 226 | |
| 227 | Expect(len(request.MultipartForm.Value)).To(Equal(0)) |
| 228 | Expect(len(request.MultipartForm.File)).To(Equal(1)) |
| 229 | |
| 230 | files, ok := request.MultipartForm.File["buildpack"] |
| 231 | Expect(ok).To(BeTrue(), "Buildpack file part not present") |
| 232 | Expect(len(files)).To(Equal(1), "Wrong number of files") |
| 233 | |
| 234 | buildpackFile := files[0] |
| 235 | file, err := buildpackFile.Open() |
| 236 | Expect(err).NotTo(HaveOccurred()) |
| 237 | |
| 238 | Expect(buildpackFile.Filename).To(ContainSubstring(".zip")) |
| 239 | |
| 240 | zipReader, err := zip.NewReader(file, 4096) |
| 241 | Expect(err).NotTo(HaveOccurred()) |
| 242 | |
| 243 | actualFileNames := []string{} |
| 244 | actualFileContents := []string{} |
| 245 | for _, f := range zipReader.File { |
| 246 | actualFileNames = append(actualFileNames, f.Name) |
| 247 | c, _ := f.Open() |
| 248 | content, _ := ioutil.ReadAll(c) |
| 249 | actualFileContents = append(actualFileContents, string(content)) |
| 250 | } |
| 251 | sort.Strings(actualFileNames) |
| 252 | |
| 253 | Expect(actualFileNames).To(Equal([]string{ |
| 254 | "bin/", |
| 255 | "bin/compile", |
| 256 | "bin/detect", |
| 257 | "bin/release", |
| 258 | "lib/", |
| 259 | "lib/helper", |
| 260 | })) |
| 261 | Expect(actualFileContents).To(Equal([]string{ |
| 262 | "", |
| 263 | "the-compile-script\n", |
| 264 | "the-detect-script\n", |
| 265 | "the-release-script\n", |
| 266 | "", |
| 267 | "the-helper-script\n", |
| 268 | })) |
| 269 | |
| 270 | if runtime.GOOS != "windows" { |
| 271 | for i := 1; i < 4; i++ { |
no test coverage detected