Skip to content

Commit 1e61f4c

Browse files
committed
Don't throw error for license embed folder
- Removed tests that are no longer applicable because we refactored to find windowsfs-release directly Co-authored-by: Michael Oleske <[email protected]> Co-authored-by: Nancy Hsieh <[email protected]> [#174372968] The `hydrate-windows2016fs-release` fails due to "there is more than one file system embedded in the tile"
1 parent 1b3a836 commit 1e61f4c

File tree

3 files changed

+33
-99
lines changed

3 files changed

+33
-99
lines changed

winfsinjector/application.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
var (
1818
readFile = ioutil.ReadFile
1919
removeAll = os.RemoveAll
20-
readDir = ioutil.ReadDir
2120
)
2221

2322
type Application struct {
@@ -70,28 +69,10 @@ func (a Application) Run(inputTile, outputTile, registry, workingDir string) err
7069
return err
7170
}
7271

73-
// find what the embedded directory is
74-
embedDirectory := filepath.Join(extractedTileDir, "embed")
75-
files, err := readDir(embedDirectory)
76-
if _, err := os.Stat(embedDirectory); os.IsNotExist(err) {
77-
return errors.New("there is no file system embedded in the tile; please contact the tile authors to fix")
72+
embeddedReleaseDir := filepath.Join(extractedTileDir, "embed/windowsfs-release")
73+
if _, err := os.Stat(embeddedReleaseDir); os.IsNotExist(err) {
74+
return errors.New("the 'windowsfs-release' file system is not embedded in the tile; please contact the tile authors to fix")
7875
}
79-
80-
if len(files) > 1 {
81-
return errors.New("there is more than one file system embedded in the tile; please contact the tile authors to fix")
82-
}
83-
84-
if len(files) == 0 {
85-
fmt.Println("The file system has already been injected in the tile; skipping injection")
86-
return nil
87-
}
88-
89-
e := files[0]
90-
if !e.IsDir() {
91-
return errors.New("the embedded file system is not a directory; please contact the tile authors to fix")
92-
}
93-
94-
embeddedReleaseDir := filepath.Join(embedDirectory, e.Name())
9576
releaseVersion, err := a.extractReleaseVersion(embeddedReleaseDir)
9677
if err != nil {
9778
return err

winfsinjector/application_test.go

Lines changed: 30 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ package winfsinjector_test
33
import (
44
"errors"
55
"fmt"
6+
"io/ioutil"
7+
"os"
8+
"path/filepath"
9+
610
. "github.com/onsi/ginkgo"
711
. "github.com/onsi/gomega"
812
"github.com/pivotal-cf/winfs-injector/winfsinjector"
913
"github.com/pivotal-cf/winfs-injector/winfsinjector/fakes"
10-
"io/ioutil"
11-
"os"
12-
"path/filepath"
1314
)
1415

1516
var _ = Describe("application", func() {
1617
Describe("Run", func() {
1718
var (
1819
fakeReleaseCreator *fakes.ReleaseCreator
19-
fakeEmbeddedDirectory *fakes.FileInfo
2020
fakeInjector *fakes.Injector
2121
fakeZipper *fakes.Zipper
2222

@@ -39,7 +39,7 @@ var _ = Describe("application", func() {
3939
outputTile = "/path/to/output/tile"
4040
registry = "/path/to/docker/registry"
4141

42-
workingDir, err = ioutil.TempDir("","")
42+
workingDir, err = ioutil.TempDir("", "")
4343
Expect(err).ToNot(HaveOccurred())
4444

4545
embedFilePath := fmt.Sprintf("%s/extracted-tile/embed", workingDir)
@@ -66,23 +66,15 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
6666
}
6767
})
6868

69-
fakeEmbeddedDirectory = new(fakes.FileInfo)
70-
fakeEmbeddedDirectory.IsDirReturns(true)
71-
fakeEmbeddedDirectory.NameReturns("windowsfs-release")
72-
73-
winfsinjector.SetReadDir(func(string) ([]os.FileInfo, error) {
74-
return []os.FileInfo{
75-
fakeEmbeddedDirectory,
76-
}, nil
77-
})
69+
err = os.MkdirAll(embedFilePath+"/windowsfs-release", os.ModePerm)
70+
Expect(err).ToNot(HaveOccurred())
7871

7972
app = winfsinjector.NewApplication(fakeReleaseCreator, fakeInjector, fakeZipper)
8073
})
8174

8275
AfterEach(func() {
8376
winfsinjector.ResetReadFile()
8477
winfsinjector.ResetRemoveAll()
85-
winfsinjector.ResetReadDir()
8678
})
8779

8880
It("unzips the tile", func() {
@@ -93,7 +85,7 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
9385

9486
inputTile, extractedTileDir := fakeZipper.UnzipArgsForCall(0)
9587
Expect(inputTile).To(Equal(filepath.Join("/", "path", "to", "input", "tile")))
96-
Expect(extractedTileDir).To(Equal(fmt.Sprintf("%s%s", workingDir,filepath.Join("/", "extracted-tile"))))
88+
Expect(extractedTileDir).To(Equal(fmt.Sprintf("%s%s", workingDir, filepath.Join("/", "extracted-tile"))))
9789
})
9890

9991
It("creates the release", func() {
@@ -143,7 +135,7 @@ windows2019fs/windows2016fs-2019.0.43.tgz:
143135
Expect(err).NotTo(HaveOccurred())
144136

145137
Expect(removeAllCallCount).To(Equal(1))
146-
Expect(removeAllPath).To(Equal(fmt.Sprintf("%s%s", workingDir,filepath.Join("/", "extracted-tile", "embed", "windowsfs-release"))))
138+
Expect(removeAllPath).To(Equal(fmt.Sprintf("%s%s", workingDir, filepath.Join("/", "extracted-tile", "embed", "windowsfs-release"))))
147139
})
148140

149141
It("zips up the injected tile dir", func() {
@@ -212,73 +204,42 @@ windows2019fs/windows2016fs-MISSING-IMAGE-TAG.tgz:
212204
})
213205
})
214206

215-
Context("when the embed directory is not a directory", func() {
207+
Context("when there is multiple directories embedded in the tile", func() {
216208
BeforeEach(func() {
217-
fakeEmbeddedDirectory = new(fakes.FileInfo)
218-
fakeEmbeddedDirectory.IsDirReturns(false)
219-
fakeEmbeddedDirectory.NameReturns("not a directory")
209+
embedFilePath := fmt.Sprintf("%s/extracted-tile/embed", workingDir)
210+
err = os.MkdirAll(embedFilePath+"/this-is-another-folder", os.ModePerm)
211+
Expect(err).ToNot(HaveOccurred())
220212
})
221213

222-
It("returns the error", func() {
214+
It("creates a release with the windowsfs-release", func() {
223215
err := app.Run(inputTile, outputTile, registry, workingDir)
224-
Expect(err).To(HaveOccurred())
225-
Expect(err).To(MatchError("the embedded file system is not a directory; please contact the tile authors to fix"))
226-
})
227-
})
216+
Expect(err).ToNot(HaveOccurred())
228217

229-
Context("when more than one file system is embedded in the tile", func() {
230-
BeforeEach(func() {
231-
winfsinjector.SetReadDir(func(string) ([]os.FileInfo, error) {
232-
return []os.FileInfo{
233-
fakeEmbeddedDirectory,
234-
fakeEmbeddedDirectory,
235-
}, nil
236-
})
237-
})
218+
Expect(fakeReleaseCreator.CreateReleaseCallCount()).To(Equal(1))
238219

239-
It("returns the error", func() {
240-
err := app.Run(inputTile, outputTile, registry, workingDir)
241-
Expect(err).To(HaveOccurred())
242-
Expect(err).To(MatchError("there is more than one file system embedded in the tile; please contact the tile authors to fix"))
220+
releaseName, imageName, releaseDir, tarballPath, imageTag, registry, version := fakeReleaseCreator.CreateReleaseArgsForCall(0)
221+
Expect(releaseName).To(Equal("windows2019fs"))
222+
Expect(imageName).To(Equal("cloudfoundry/windows2016fs"))
223+
Expect(releaseDir).To(Equal(fmt.Sprintf("%s/extracted-tile/embed/windowsfs-release", workingDir)))
224+
Expect(tarballPath).To(Equal(fmt.Sprintf("%s/extracted-tile/releases/windows2019fs-9.3.6.tgz", workingDir)))
225+
Expect(imageTag).To(Equal("2019.0.43"))
226+
Expect(registry).To(Equal("/path/to/docker/registry"))
227+
Expect(version).To(Equal("9.3.6"))
243228
})
244229
})
245230

246-
Context("when there are no file systems embedded in the tile", func() {
231+
Context("when windowsfs-release is not embedded in the tile", func() {
247232
BeforeEach(func() {
248-
workingDir = "not/a/path/to/tile"
249-
winfsinjector.SetReadDir(func(string) ([]os.FileInfo, error) {
250-
return []os.FileInfo{}, nil
251-
})
233+
embedFilePath := fmt.Sprintf("%s/extracted-tile/embed", workingDir)
234+
os.RemoveAll(embedFilePath + "/windowsfs-release")
235+
err = os.MkdirAll(embedFilePath+"/this-is-another-folder", os.ModePerm)
236+
Expect(err).ToNot(HaveOccurred())
252237
})
253238

254239
It("returns the error", func() {
255240
err := app.Run(inputTile, outputTile, registry, workingDir)
256241
Expect(err).To(HaveOccurred())
257-
Expect(err).To(MatchError("there is no file system embedded in the tile; please contact the tile authors to fix"))
258-
})
259-
})
260-
261-
Context("when the file system has already been injected", func() {
262-
BeforeEach(func() {
263-
winfsinjector.SetReadDir(func(string) ([]os.FileInfo, error) {
264-
return []os.FileInfo{}, nil
265-
})
266-
})
267-
268-
It("does not return an error and exits", func() {
269-
var err error
270-
r, w, _ := os.Pipe()
271-
tmp := os.Stdout
272-
defer func() {
273-
os.Stdout = tmp
274-
}()
275-
os.Stdout = w
276-
err = app.Run(inputTile, outputTile, registry, workingDir)
277-
w.Close()
278-
279-
Expect(err).ToNot(HaveOccurred())
280-
stdout, _ := ioutil.ReadAll(r)
281-
Expect(string(stdout)).To(ContainSubstring("The file system has already been injected in the tile; skipping injection"))
242+
Expect(err).To(MatchError("the 'windowsfs-release' file system is not embedded in the tile; please contact the tile authors to fix"))
282243
})
283244
})
284245

winfsinjector/exports_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,3 @@ func SetRemoveAll(f func(string) error) {
2020
func ResetRemoveAll() {
2121
removeAll = os.RemoveAll
2222
}
23-
24-
func SetReadDir(f func(string) ([]os.FileInfo, error)) {
25-
readDir = f
26-
}
27-
28-
func ResetReadDir() {
29-
readDir = ioutil.ReadDir
30-
}

0 commit comments

Comments
 (0)