migueleliasweb / go-github-mock

A library to aid unittesting code that uses Golang's Github SDK
MIT License
98 stars 24 forks source link

Fails to handle GetArchiveLink routes #18

Closed edwardofclt closed 2 years ago

edwardofclt commented 2 years ago

Using the following logic (with a custom EndpointPattern because the already existing pattern assumes you're specifying a ref) I get an Get "": unsupported protocol scheme "" response.

mock.WithRequestMatchHandler(mock.EndpointPattern{
  Pattern: "/repos/{owner}/{repo}/zipball",
  Method:  "GET",
}, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
  rw.WriteHeader(http.StatusFound)
  rw.Header().Add("Location", "https://codeload.github.com/gothinkster/react-redux-realworld-example-app/legacy.zip/refs/heads/master")
})),

I'm unsure if what I'm doing is inherently wrong, but I believe I'm returning the same response that Github would return with the http.StatusFound response and with a header identifying the location of the requested zipball.


Also, let me just say, I really appreciate this project - it's gotten me 95% of the way where I need to be for a project I'm working on. So, thank you!

migueleliasweb commented 2 years ago

Hi @edwardofclt ,

could you paste here the SDK method you're running?

migueleliasweb commented 2 years ago

I just noticed there is a possible improvement to the mock framework where the optional parameters are used to generate endpoints without them so the calls can succeed.

migueleliasweb commented 2 years ago

It appears, even the OpenApiSpec for the Github API says all parameters for the endpoint /repos/{owner}/{repo}/zipball/{ref} are required but the description explains otherwise :disappointed: .

Even the go-github SDK handles it in a weird way by appending the ref if it's present. :disappointed:

See:

This seems to be an edge case.

edwardofclt commented 2 years ago

No worries, I'm using the GetArchiveLink method. I noticed the same thing in the go-github package. Thought it was odd.

edwardofclt commented 2 years ago

@migueleliasweb about to sign off for the rest of the year - any tips on how to make this endpoint work?

migueleliasweb commented 2 years ago

I have an idea how to mitigate this but it will require some substantial changes to the internals of the way requests are configured in the mock server.

The main problem seems to be the expected HTTP status and header is quite specific for this endpoint.

I probably won't be able to have enough time to fix this today, I'm sorry.

If you have the time, feel free to raise a PR and I will be happy to review.

migueleliasweb commented 2 years ago

Hi @edwardofclt ,

I might have found a workaround. I took most of your example, so thank you. Can you try to use https://github.com/migueleliasweb/go-github-mock/pull/20 and see if it suits you?

edwardofclt commented 2 years ago

Awesome! Thanks, I'll give it a go soon.

migueleliasweb commented 2 years ago

@edwardofclt Any updates on this?

migueleliasweb commented 2 years ago

I will be closing this for now.