Closed LeoQuote closed 2 years ago
Oh boi, this seems to be an interesting edge case.
The {path}
can actually contain forward slashes (I was unaware of that, tbh) and that seems to break the URL parsing for this endpoint. Without /
in the path, the matching works.
hmm, I should urlencode this {path}
or this is regarded as bug ?
I think I have a plan but that might require some extra smarts during the generation of the endpoints pattern in order to account for edge cases ( I'm sure there will be more eventually )
I can probably get this working soon-ish.
I will mark this as a bug.
Hi @LeoQuote, can you test the branch from https://github.com/migueleliasweb/go-github-mock/pull/27.
Let me know if it fixes your problem.
Thanks for your quick response, will try it next week!
hmmm maybe releavant , I tried to mock PatchReposGitRefsByOwnerByRepoByRef
also failed .
mockedHTTPClient := mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.GetReposByOwnerByRepo,
github.Repository{
DefaultBranch: github.String("base"),
Name: github.String("repo-name"),
}),
mock.WithRequestMatch(
mock.PatchReposGitRefsByOwnerByRepoByRef,
github.Reference{
Ref: github.String("refs/heads/new-branch"),
}),
)
c := github.NewClient(mockedHTTPClient)
ctx := context.Background()
_, _, err := c.Git.UpdateRef(ctx, "owner", "repo-name", &github.Reference{
Ref: github.String("refs/heads/new-branch"),
Object: &github.GitObject{SHA: github.String("fake-sha")},
}, false)
assert.Nil(t, err)
github_test.go:101:
Error Trace: github_test.go:101
Error: Expected nil, but got: &github.ErrorResponse{Response:(*http.Response)(nil), Message:"mock response not found for /repos/owner/repo-name/git/refs/heads/new-branch", Errors:[]github.Error(nil), Block:(*github.ErrorBlock)(nil), DocumentationURL:""}
Test: TestPush
@LeoQuote yeah, it's similar problem to the GetContents
call. I will also fix that and create a new release.
@LeoQuote Can you test again your cases with https://github.com/migueleliasweb/go-github-mock/pull/30? It should cater for both cases.
if I call it with
it will raise exception
seems to be the path could not match pattern