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

blob.go: adapt code to use helpers for paths #19

Merged
merged 2 commits into from Feb 3, 2015
Merged

Conversation

jf
Copy link
Contributor

@jf jf commented Jan 29, 2015

No description provided.

@ahmetb
Copy link
Contributor

ahmetb commented Jan 29, 2015

I actually have a better plan. Do you mind creating methods like pathForContainer and pathForBlob then we can get rid of all those duplication of fmt.Sprintfs and have the path logic only in one place?

@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

Well now that is better alright!

@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

@ahmetalpbalkan are you ok with these methods being called, and the results used directly without any intermediate "path" variable? There are no error returns with fmt.Sprintf; it always returns a string.

so eg.

uri := b.client.getEndpoint(blobServiceName, b.pathForBlob(container, name), url.Values{})

instead of

path := fmt.Sprintf("%s/%s", container, name)
uri := b.client.getEndpoint(blobServiceName, path, url.Values{})

Also, what would you have these be methods of? StorageClient? BlobStorageClient? or should they be generic methods, and be put in util.go?

@ahmetb
Copy link
Contributor

ahmetb commented Jan 29, 2015

yeah I'm ok (as long as there's nothing complicated on that line except calling pathForBlob), these can go to blob.go as global non-exported functions. there's no need to make it functions of BlobStorageClient.

oh also, unit tests for those can go to blob_test.go

@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

Actually we dont need a pathForContainer, do we? Just pathForBlob.

@ahmetb
Copy link
Contributor

ahmetb commented Jan 29, 2015

you actually do. what happens when tomorrow we want to address containers as /{container} in the code? :) you need to change 20 different places instead of 1. that logic must be only in one place and it should be testable. that's why these helpers are crucial.

@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

eh... well I guess you're right. I was focussed on the present. :}

@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

@ahmetalpbalkan , this is what I have so far (minus the tests). Let me know what you think.

Note: I've added a / at the front of the constructed paths because that's what will happen anyway (see http://golang.org/src/net/url/url.go?s=12230:12259#L452, line 481). I'm shortcutting the code, and making things clearer imo.

(And of course, the current tests pass with this code).

@ahmetb
Copy link
Contributor

ahmetb commented Jan 29, 2015

Nope please don't add that. That duplicates the job of net/url package and might have introduced bugs elsewhere. I wouldn't do that unless it's very necessary. (Did you also run the test suite with this change?)

@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

Yes I did (added that in my comment after I first posted it). I don't think it really duplicates the work of the code in net/url, though. I see that line (in net/url as I pointed) as just a precaution, or "helper" of sorts ("if the slash isn't prepended, we'll prepend it").

Paths are after all meant to start with a /, right? And I would prefer to make that clear, because I was wondering that myself when I first came to this code. I had to go dig into the code for getEndpoint(), and then net/url's "url.String" before I understood that it was ok not to have that / at the front.

@ahmetb
Copy link
Contributor

ahmetb commented Jan 29, 2015

Okay I guess it's okay unless it makes requests with double slashes (//) or generates GetBlobURL or SAS URL like that. These are already covered by the tests. I will take a final look and then merge. Thanks @jf.

@ahmetb
Copy link
Contributor

ahmetb commented Jan 29, 2015

Oh and I realized pathForBlob can reuse pathForContainer. 😄 also having simple unit tests would be really great. Thanks.

@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

ha, I never really considered that! Do you want to keep them separate, though? or are we worrying too much?

I'll get some tests in.

@ahmetb ahmetb changed the title blob.go, ContainerExists(): remove unnecessary Sprintf blob.go: adapt code to use helpers for paths Jan 29, 2015
@jf
Copy link
Contributor Author

jf commented Jan 29, 2015

ok I've just added the tests. Had to figure out (took some troubleshooting!) why no matter what I did, the tests I added weren't running. So it turns out I found a bug in blob_test.go, and fixed that too. I'm choosing to keep the fix in a separate commit, because I think it's important enough to point out. Prior to this, we weren't running the test for blobSASStringToSign() (and it was wrong to boot, too), apparently!

func Test_pathForBlob(t *testing.T) {
out := pathForBlob("foo", "blob")
if expected := "/foo/blob"; out != expected {
t.Errorf("Wrong pathForContainer. Expected: '%s', got: '%s'", expected, out)
Copy link
Contributor

Choose a reason for hiding this comment

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

pathForBlob

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:}

@jeffmendoza
Copy link

@jf can you sign a CLA at https://cla.msopentech.com/ ?

@ahmetb
Copy link
Contributor

ahmetb commented Jan 29, 2015

Please rebase on top of master to include the CI commit, otherwise test will fail.

@jf
Copy link
Contributor Author

jf commented Jan 30, 2015

@jeffmendoza is there a more specific privacy policy for developers/open source contributors? I don't see how getting my address, for example, is necessary

@jeffmendoza
Copy link

Looks like there is a link at the end of the page to here: https://msopentech.com/privacy-policy/

@jf
Copy link
Contributor Author

jf commented Jan 30, 2015

I'm aware and have already looked through it. That's a generic one for all of "MS Open Tech" - "Msopentech.com and other Microsoft Open Technologies, Inc. (“MS Open Tech”) websites and services of MS Open Tech that collect data and display these terms, as well as its offline product support services.". Perhaps some of these will have a legitimate reason for asking for an address.... but as a "pure github contributor and nothing else", I see no reason for Microsoft to ask for my address.

@jf
Copy link
Contributor Author

jf commented Jan 30, 2015

Anyway, I've filled in the form. But haven't received any email yet. Is it automated? or manual? (so ie. a delay is normal)

@ahmetb
Copy link
Contributor

ahmetb commented Feb 2, 2015

@hopetobelievein is CLA approved for @jf ?

@jeffmendoza
Copy link

@jf Looks like our new system just took over, can you try: https://cla2.msopentech.com/

@jf
Copy link
Contributor Author

jf commented Feb 2, 2015

Ok I'm going to give it one more try. But if this doesn't go through, I'm out for submitting PRs.

@ahmetb
Copy link
Contributor

ahmetb commented Feb 3, 2015

@jeffmendoza is CLA approved for @jf?

@jf
Copy link
Contributor Author

jf commented Feb 3, 2015

I am approved already, @ahmetalpbalkan . But dunno if this is good enough for you, or if you're required to hear from one of the folks you've asked first (in which case, we need to wait on them).

@ahmetb
Copy link
Contributor

ahmetb commented Feb 3, 2015

@jf ah okay, it is just I don't have access to the interface that shows if you're approved or not. I did not realize you got the approval email from the context above.

ahmetb added a commit that referenced this pull request Feb 3, 2015
blob.go: use helper methods for creating paths
@ahmetb ahmetb merged commit 0d03132 into Azure:master Feb 3, 2015
@jeffmendoza
Copy link

@jf Thanks for bearing with us

marstr pushed a commit to marstr/azure-sdk-for-go that referenced this pull request Apr 27, 2017
marstr pushed a commit that referenced this pull request Apr 28, 2017
mcardosos added a commit that referenced this pull request May 4, 2017
richardpark-msft pushed a commit to richardpark-msft/azure-sdk-for-go that referenced this pull request Aug 5, 2021
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.

None yet

3 participants