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: #29 #52

Closed
wants to merge 19 commits into from
Closed

fix: #29 #52

wants to merge 19 commits into from

Conversation

mrinalwahal
Copy link

Opening this PR as submission of my coding assignment.

This PR merges the following changes:

  1. Fixes text.ResolveFile #29.
  2. Adds ResolveFile() and ResolveFiles() functions.
  3. Test function for ResolveFile() with a correct filename as input, a directory and a URL.

NOTE:

  1. I've limited my solution strictly to the minimal description of issue text.ResolveFile #29.
  2. I'm NOT very confident about either the utility of these 2 functions or my solutions. Here's why:
  • I'm not sure why such simple functions were even required.
  • Description on the issue page wasn't very explanatory.
  • ResolveFiles() should ideally not exist. I'd say you should write a range to resolve multiple files whenever and wherever required. Its response is also not apt. There are better ways to return errors if any of those files can't be resolved. But I've kept the response strictly identical to the issue description.

@CLAassistant
Copy link

CLAassistant commented Sep 10, 2022

CLA assistant check
All committers have signed the CLA.

@mrinalwahal mrinalwahal marked this pull request as ready for review September 11, 2022 11:24
files/files.go Outdated
func Getter(source, dst string) error {

// Validate the URL first.
url, err := url.ParseRequestURI(source)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to validate the URL first? Are we sure that url.ParseRequestURI will not return an error for all URLS/URI's supported by go-getter ?

Copy link
Author

@mrinalwahal mrinalwahal Sep 11, 2022

Choose a reason for hiding this comment

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

I think you are right. I added the URI parser primarily for branching the code to handle local files and URLs separately. But then I forgot I shifted it to ResolveFile() function. I'm pushing the change.

files/files.go Outdated
//
// This will validate both a file in the filesystem,
// as well as the URL source for a file.
if filepath.Ext(file) == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Why does a file or URL need an extension?

$value == 1.00 is not a valid path or URL, yet would pass this test?

And likewise
/etc/hosts is a valid path ?

Copy link
Author

Choose a reason for hiding this comment

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

Aah, I only added the extension check to return an error if its a directory instead of a file. I totally forgot about files like /etc/hosts with no extensions. Let me improve this.

files/files.go Outdated
// Ensure the scheme is HTTP or HTTPS.
if err == nil &&
url.Scheme != "" &&
(strings.ToLower(url.Scheme) == "http" ||
Copy link
Member

Choose a reason for hiding this comment

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

What about the other schemes supported by go-getter ?

Copy link
Author

Choose a reason for hiding this comment

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

I only added the scheme check because FS files came with file:// scheme. And I wanted to exclude them. Because the url.ParseRequestURI(source) method is parsing even the URLs without a host as valid ones. So, I needed a quick way out.

Copy link
Author

@mrinalwahal mrinalwahal Sep 11, 2022

Choose a reason for hiding this comment

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

Oh, wait! I didn't know that go-getter also supports local files. I just checked their docs. I thought it only supported remote files over networks 🤦

This calls for changing the entire function code now.

Apologies for this mishap! I'll get this done.

Copy link
Author

Choose a reason for hiding this comment

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

@moshloop, should I add an extra argument for the destination to where we have to resolve the file? The issue description doesn't mention it, that's why I am asking. In absence of a valid destination, I'll initialize a temporary directory to resolve the files over there.

Copy link
Author

@mrinalwahal mrinalwahal Sep 11, 2022

Choose a reason for hiding this comment

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

Pushed new changes. Supports all go-getter schemes now 👍 Including git://. Added a new test for it.

@moshloop
Copy link
Member

@mrinalwahal can you check the test failures? We can also drop support for 1.16

@mrinalwahal
Copy link
Author

@mrinalwahal can you check the test failures? We can also drop support for 1.16

The test errors are related to net/http dependency not being located in GH Actions containers. I've updated the go.mod and go.sum files and dropped support for 1.13. Updated to 1.18.

Let me know if anything more is required.

@Kaitou786
Copy link
Contributor

@mrinalwahal can you check the test failures? We can also drop support for 1.16

The test errors are related to net/http dependency not being located in GH Actions containers. I've updated the go.mod and go.sum files and dropped support for 1.13. Updated to 1.18.

Let me know if anything more is required.

Since you updated the go version in go.mod to 1.18 we won't have the go1.17 working with test... But we would need to support it so I suggest support from 1.17 and then fix the go.mod

@mrinalwahal
Copy link
Author

mrinalwahal commented Sep 20, 2022

@mrinalwahal can you check the test failures? We can also drop support for 1.16

The test errors are related to net/http dependency not being located in GH Actions containers. I've updated the go.mod and go.sum files and dropped support for 1.13. Updated to 1.18.
Let me know if anything more is required.

Since you updated the go version in go.mod to 1.18 we won't have the go1.17 working with test... But we would need to support it so I suggest support from 1.17 and then fix the go.mod

Hey @Kaitou786, I've also tried adding support from both 1.16 and 1.17 onward. But dependency management is breaking. Refreshed the go.sum and go.mod files as well for the same. Tests are still failing.

Also, I'd suggest from 1.16 onward because you seem to be running tests for it.

And the error is always coming from the same package i.e. github.com/hairyhenderson/gomplate. I think this package has issues in compiling with 1.16 onward.

@Kaitou786
Copy link
Contributor

Also, I'd suggest from 1.16 onward because you seem to be running tests for it.

So would need to make pin to 1.16 on the go.mod?

And the error is always coming from the same package i.e. github.com/hairyhenderson/gomplate. I think this package has issues in compiling with 1.16 onward.

you can try updating the GH setup/go action... I am able to compile your code locally with go1.17

@mrinalwahal
Copy link
Author

So the checks seem to have worked with support only from Go 1.18 onward.

But let me experiment once again with Go 1.17. If it doesn't work, we can switch to 1.18 again.

@Kaitou786 @moshloop

@mrinalwahal
Copy link
Author

Nope! Tried adding support for Go 1.17 and package github.com/hairyhenderson/gomplate once again threw errors.

So, I'm sticking with support from Go 1.18 onward only.

@moshloop moshloop closed this Jun 14, 2023
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.

text.ResolveFile
4 participants