migueleliasweb / go-github-mock

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

Last param should match slashes #43

Closed raffis closed 1 year ago

raffis commented 1 year ago

Currently I have to override this endpoint pattern:

var deleteReposIssuesLabelsByOwnerByRepoByIssueNumberByName mock.EndpointPattern = mock.EndpointPattern{
    Pattern: "/repos/{owner}/{repo}/issues/{issue_number}/labels/{name:.*}",
    Method:  "DELETE",
}

The default is to generate it like: "/repos/{owner}/{repo}/issues/{issue_number}/labels/{name}" However mux would not match an URL like repos/foo/bar/issues/3/labels/prio/high

The label name contains a slash which is valid in github and that api call also works. However it does not work using the mock as mux does not route it correctly and it ends in mock response not found for /repos/foo/bar/issues/3/labels/prio/high

Happy to provide a fix for the generator if this is considered a bug.

migueleliasweb commented 1 year ago

Hi @raffis , there are some other known edge cases like this in Github's API. They're quite inconsistent.

As you can see in https://github.com/migueleliasweb/go-github-mock/blob/master/src/gen/gen_mutations.go#L9, there have been a few instances already. What that mutator does is basically intercept the generation process and mutate the final param to be something that would accept any character. Have a look.

I'm happy to let you add this use-case to that file.

Let me know your thoughts.

raffis commented 1 year ago

Let me know your thoughts.

Thats perfect, thanks 👍🏻 , see #44