func GenerateLightStemcellTarball(lightStemcellMF LightStemcellMF, lightStemcellInfo LightStemcellInfo, lightStemcellsPath string) (string, error) { lightStemcellMFBytes, err := GenerateManifestMFBytesYAML(lightStemcellMF) lightStemcellMFFilePath := filepath.Join(lightStemcellsPath, "stemcell.MF") err = ioutil.WriteFile(lightStemcellMFFilePath, lightStemcellMFBytes, 0666) if err != nil { return "", errors.New(fmt.Sprintf("Could not create stemcell.MF file, error: `%s`", err.Error())) } imageFilePath := filepath.Join(lightStemcellsPath, "image") err = ioutil.WriteFile(imageFilePath, []byte{}, 0666) if err != nil { return "", errors.New(fmt.Sprintf("Could not create image file, error: `%s`", err.Error())) } lightStemcellFilePath := filepath.Join(lightStemcellsPath, fmt.Sprintf("%s.tgz", GenerateStemcellFilelName(lightStemcellInfo))) err = common.CreateTarball(lightStemcellFilePath, []string{lightStemcellMFFilePath, imageFilePath}) if err != nil { return "", errors.New(fmt.Sprintf("Could not create tarball file, error: `%s`", err.Error())) } err = os.Remove(lightStemcellMFFilePath) if err != nil { return "", errors.New(fmt.Sprintf("Could clean up temp file '%s', error: `%s`", lightStemcellMFFilePath, err.Error())) } err = os.Remove(imageFilePath) if err != nil { return "", errors.New(fmt.Sprintf("Could clean up temp file '%s', error: `%s`", imageFilePath, err.Error())) } return lightStemcellFilePath, nil }
tarballFileName = tmpFile.Name() }) AfterEach(func() { err = os.Remove(tarballFileName) Expect(err).NotTo(HaveOccurred()) for _, fileName := range tarballFileNames { err = os.Remove(fileName) Expect(err).NotTo(HaveOccurred()) } }) It("creates a tarball", func() { err = common.CreateTarball(tarballFileName, tarballFileNames) Expect(err).NotTo(HaveOccurred()) }) }) Context("ReadJsonTestFixtures", func() { type Test struct { Test string `json:"test"` } It("reads the test_fixtures/test/test.json", func() { contents, err := common.ReadJsonTestFixtures("..", "test", "test.json") Expect(err).NotTo(HaveOccurred()) test := Test{} err = json.Unmarshal(contents, &test)