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

fix(compute/init): Init no longer fails if directory of same name as starter kit exists in current directory #1349

Merged
merged 7 commits into from
Nov 20, 2024

Conversation

harmony7
Copy link
Member

@harmony7 harmony7 commented Nov 18, 2024

Resolves #1255.

This PR resolves the issue by placing the temporary file created during the download performed by fastly compute init --from in a temporary directory rather than the current directory.

Notes:

  • This PR adds a setupSteps member to the test table in init_test, and runs those steps as part of the initialization of each test.

  • This PR adds a few new test cases to init_test that uses the above setupSteps mechanism to create a directory with the same name as the starter kit before calling fastly compute init.

  • The existing defer cleanup done to remove the temporary file has been removed, because the cleanup code for the temporary directory will clean it up.

…as starter kit exists in the current directory
@harmony7 harmony7 force-pushed the kats/compute-init-existingdir branch 3 times, most recently from 1981706 to 51c590e Compare November 18, 2024 15:15
@harmony7 harmony7 marked this pull request as ready for review November 18, 2024 15:17
@harmony7 harmony7 changed the title DRAFT: fix(compute/init): Init no longer fails if directory of same name as starter kit exists in current directory fix(compute/init): Init no longer fails if directory of same name as starter kit exists in current directory Nov 18, 2024
@harmony7 harmony7 force-pushed the kats/compute-init-existingdir branch from 51c590e to 5889db0 Compare November 18, 2024 16:29
Copy link
Contributor

@kpfleming kpfleming left a comment

Choose a reason for hiding this comment

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

Some minor Go style changes, but otherwise this looks great!

pkg/commands/compute/init_test.go Outdated Show resolved Hide resolved
pkg/commands/compute/init_test.go Show resolved Hide resolved
pkg/commands/compute/init.go Show resolved Hide resolved
pkg/commands/compute/init.go Outdated Show resolved Hide resolved
Co-authored-by: Kevin P. Fleming <[email protected]>
@harmony7
Copy link
Member Author

Thanks for your review! I've applied the changes from your suggestions, please review again. Go ahead and merge it if you approve it as I will be away for the next few days.

@harmony7
Copy link
Member Author

This pattern occurred many more times in this file so I applied it there too:

-spinErr := spinner.StopFail()
-if spinErr != nil {
+if spinErr := spinner.StopFail(); spinErr != nil {

(We may want to consider factoring this out)

@harmony7
Copy link
Member Author

I had to revert the inlined assign/compare pattern for a couple of the cases because the variables that were assigned needed to be available later, outside the if block. I don't know if there's a Go-style best practice for this kind of pattern.

@kpfleming
Copy link
Contributor

There is... use var <name> <type> before the if block, so that the declaration becomes independent of the block. It's not a big deal though.

@kpfleming kpfleming merged commit 3c7d993 into main Nov 20, 2024
9 checks passed
@kpfleming kpfleming deleted the kats/compute-init-existingdir branch November 20, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants