Skip to content
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

Check if folder exists before attempting to copy folders #743

Merged
merged 4 commits into from
Jan 28, 2021

Conversation

cbuto
Copy link
Contributor

@cbuto cbuto commented Dec 19, 2020

This PR attempts to close #738.

I ran through the unit tests that were affected by these changes. I'm not sure if the output is super useful for those but I also ran some of the automated tests that use CopyTerraformFolderToTemp which look good. I was unable to run the full automated test suite right now, but I can look at doing at later if needed.

Here is the output from the automated test I did run:

https://gist.github.com/cbuto/13dd83b40d29503288b11192ee2c4149

@cbuto cbuto changed the title Check if folder exists before attempting to copy folders to allow f Check if folder exists before attempting to copy folders Dec 19, 2020
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

modules/files/files.go Outdated Show resolved Hide resolved
modules/files/files.go Outdated Show resolved Hide resolved
modules/files/files_test.go Outdated Show resolved Hide resolved
modules/files/files_test.go Outdated Show resolved Hide resolved
modules/test-structure/test_structure.go Outdated Show resolved Hide resolved
return "", err
}
if !exists {
return "", os.ErrNotExist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Could you create a new error that includes the path of the non-existent folder in the error message? That'll help quite a bit with debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this to include the folderPath. I wonder if I should also use that same error message here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please! In fact, we typically define a new type that implements the error interface (has an Error() method), so that (a) you can check if the error you got back was of a specific type, rather than doing string parsing and (b) you can re-use that error type in more than one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, I created DirNotFoundError. Let me know if that's what you were thinking!

modules/files/files_test.go Outdated Show resolved Hide resolved
modules/files/files_test.go Outdated Show resolved Hide resolved
modules/test-structure/test_structure.go Outdated Show resolved Hide resolved
t.Fatal(err)
}
if !exists {
t.Fatal(os.ErrNotExist, fullTerraformModuleFolder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this show a clear error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in:

TestTerraformAwsExamplePlan: test_structure.go:82: file does not exist ../no/examples/terraform-aws-example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's decent, but would be slightly better if it said "directory" instead of file. If you extract + reuse the error type as mentioned above, that'll do the trick.

@cbuto
Copy link
Contributor Author

cbuto commented Jan 7, 2021

@brikis98 Thanks for taking the time to review this, I appreciate it!

@cbuto cbuto requested a review from brikis98 January 8, 2021 22:54
brikis98
brikis98 previously approved these changes Jan 13, 2021
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! I'll kick off tests now.

@brikis98
Copy link
Member

Ah, doh, I forgot we have a couple random test failures, and we're working on a fix now: #756. Let's get that merged first, and then I can re-run the tests here.

@cbuto
Copy link
Contributor Author

cbuto commented Jan 13, 2021

Cool thanks! Let me know if I can help at all

@cbuto
Copy link
Contributor Author

cbuto commented Jan 27, 2021

I rebased this PR with master to pull in the test updates

@brikis98
Copy link
Member

Thanks! I'll re-run tests now.

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests passed! Merging now, thank you!

@brikis98 brikis98 merged commit 15b2b94 into gruntwork-io:master Jan 28, 2021
@brikis98
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_structure.CopyTerraformFolderToTemp - verify terraformModuleFolder exists
2 participants