Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Modifies detection to fail if there is a vendor directory present in …
Browse files Browse the repository at this point in the history
…the working directory (#14)

Signed-off-by: Sophie Wigmore <[email protected]>

Co-authored-by: Arjun Sreedharan <[email protected]>
  • Loading branch information
sophiewigmore and arjun024 authored Jul 23, 2020
1 parent 72ddc6d commit 67f8efd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
11 changes: 10 additions & 1 deletion detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ func Detect() packit.DetectFunc {
if os.IsNotExist(err) {
return packit.DetectResult{}, packit.Fail
}
return packit.DetectResult{}, fmt.Errorf("Failed to stat Gopkg.toml : %w", err)
return packit.DetectResult{}, fmt.Errorf("failed to stat Gopkg.toml: %w", err)
}

_, err = os.Stat(filepath.Join(context.WorkingDir, "vendor"))
if err == nil {
return packit.DetectResult{}, packit.Fail
} else {
if !os.IsNotExist(err) {
return packit.DetectResult{}, fmt.Errorf("failed to stat vendor directory: %w", err)
}
}

return packit.DetectResult{
Expand Down
32 changes: 32 additions & 0 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,36 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Expect(err).To(MatchError(packit.Fail))
})
})

context("when there is a vendor directory in the working directory", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(workingDir, "vendor"), os.ModePerm)).To(Succeed())
})

it("fails detection", func() {
_, err := detect(packit.DetectContext{
WorkingDir: workingDir,
})
Expect(err).To(MatchError(packit.Fail))
})
})

context("failure cases", func() {
context("the workspace directory cannot be accessed", func() {
it.Before(func() {
Expect(os.Chmod(workingDir, 0000)).To(Succeed())
})

it.After(func() {
Expect(os.Chmod(workingDir, os.ModePerm)).To(Succeed())
})

it("returns an error", func() {
_, err := detect(packit.DetectContext{
WorkingDir: workingDir,
})
Expect(err).To(MatchError(ContainSubstring("failed to stat Gopkg.toml:")))
})
})
})
}

0 comments on commit 67f8efd

Please sign in to comment.