-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce fs.FileExists #160
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
andymoe
force-pushed
the
add-fs-file-exists
branch
3 times, most recently
from
April 17, 2021 07:33
4dac6fb
to
7f549f0
Compare
andymoe
force-pushed
the
add-fs-file-exists
branch
from
April 17, 2021 21:30
7f549f0
to
a8690b6
Compare
I'd like to see a couple changes:
context("when we are testing for a directory", func() {
- var subDir = filepath.Join(dirPath, "sub-dir")
+ var subDir string
+
+ it.Before(func() {
+ subDir = filepath.Join(dirPath, "sub-dir")
+ Expect(os.Mkdir(subDir, os.ModePerm)).To(Succeed())
+ })
+
context("and a directory exists", func() {
it("returns true", func() {
- Expect(os.Mkdir(subDir, os.ModePerm)).To(Succeed())
- Expect(fs.FileExists(dirPath)).To(BeTrue())
+ Expect(fs.FileExists(subDir)).To(BeTrue())
})
})
+
context("when the directory does not exist", func() {
it.Before(func() {
- Expect(os.RemoveAll(dirPath)).To(Succeed())
+ Expect(os.RemoveAll(subDir)).To(Succeed())
})
it("returns false", func() {
- Expect(fs.FileExists(dirPath)).To(BeFalse())
+ Expect(fs.FileExists(subDir)).To(BeFalse())
})
})
@@ -97,12 +104,10 @@ func testFileExists(t *testing.T, context spec.G, it spec.S) {
Expect(os.Chmod(dirPath, os.ModePerm)).To(Succeed())
})
- // With this setup we keep getting nil error which I don't understand.
- // I'm clearly missing something.
it("returns false and an error", func() {
- exits, err := fs.FileExists(subDir)
- Expect(err.Error()).To(ContainSubstring("<syscall.Errno>0xd"))
- Expect(exits).To(BeFalse())
+ exists, err := fs.FileExists(subDir)
+ Expect(err).To(MatchError(ContainSubstring("permission denied")))
+ Expect(exists).To(BeFalse())
})
})
}) |
Thanks! I'll get this fixed up. I really got myself confused with the scoping there... |
@andymoe @ryanmoran Is the only thing that this is waiting on changing the name of the function to be more generic? I would love to move this along because the ask seems relatively straight forward. |
Yeah, sorry. I had some issues with my tests etc too and I never got back
to it and sorted it out locality.
…On Wed, Jun 9, 2021 at 12:01 PM Forest Eckhardt ***@***.***> wrote:
@andymoe <https://github.com/andymoe> @ryanmoran
<https://github.com/ryanmoran> Is the only thing that this is waiting on
changing the name of the function to be more generic? I would love to move
this along because the ask seems relatively straight forward.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#160 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACTA4IJWRJVH7QL6HHLGDTR63APANCNFSM43CTH4RA>
.
|
@andymoe Bump |
Drafting this for now since there has not been a code update since April. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds a the method
FileExists
to thefs
sub package. This is code we found ourselves needing more than a couple places in theconda-env-update
buildpack.Also alphabetized suite call order in
fs/init_test.go
Use Case
Note: this PR does not have test cases for using this method against a directory. While we have more test coverage than
libbuildpack
does I've not been able to figure out how to correctly test this case properly. The additional (broken/wrong) tests for a fs.FileExists(/my/missing/directory
) are on this branch if you have ideas/feedback.