diff --git a/detect.go b/detect.go index e4b3066..58f0360 100644 --- a/detect.go +++ b/detect.go @@ -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{ diff --git a/detect_test.go b/detect_test.go index 9a4fc03..3b80444 100644 --- a/detect_test.go +++ b/detect_test.go @@ -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:"))) + }) + }) + }) }