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

Unable to mock Git.GetRef #24

Closed
oba11 opened this issue Mar 23, 2022 · 8 comments
Closed

Unable to mock Git.GetRef #24

oba11 opened this issue Mar 23, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@oba11
Copy link

oba11 commented Mar 23, 2022

I tried mocking Git.GetRef but unable to make it work

mockedHTTPClient := mock.NewMockedHTTPClient(
	mock.WithRequestMatch(
		mock.GetReposGitRefByOwnerByRepoByRef,
		github.Reference{},
	),
)
c := github.NewClient(mockedHTTPClient)
ctx := context.Background()

reference, resp, err := c.Git.GetRef(ctx, "foo", "bar", "main")
log.Println(reference)
log.Println(resp.Response.StatusCode)
log.Println(resp.Response.Request)

// time="2022-03-23T12:21:53+04:00" level=info msg="<nil>"
// time="2022-03-23T12:21:53+04:00" level=info msg=404
// time="2022-03-23T12:21:53+04:00" level=info msg="&{GET http://127.0.0.1:55565/repos/foo/bar/git/ref/main HTTP/1.1 1 1 map[Accept:[application/vnd.github.v3+json] User-Agent:[go-github]] <nil> <nil> 0 [] false api.github.com map[] map[] <nil> map[]   <nil> <nil> <nil> 0xc00001c0b0}"

I tried similar mock with c.Git.CreateRef and works fine.
Anything I'm doing wrong that should be changed?

@migueleliasweb
Copy link
Owner

Hi @oba11 , could you try using GetReposGitRefByOwnerByRepoByRef instead?

By looking inside the go-github GetRef() definitions, looks like it's requesting "repos/%v/%v/git/ref/%v". This URL doesn't match PostReposGitRefsByOwnerByRepo but it should work with GetReposGitRefByOwnerByRepoByRef.

👍

@oba11
Copy link
Author

oba11 commented Mar 23, 2022

@migueleliasweb my apologies, it was a typo which I've corrected. I tried it with GetReposGitRefByOwnerByRepoByRef but didn't seem to work

@migueleliasweb
Copy link
Owner

I will have a better look soon, @oba11 .

@oba11
Copy link
Author

oba11 commented Mar 28, 2022

Thank you @migueleliasweb 🙏

@migueleliasweb
Copy link
Owner

Hi @oba11 , could you check for me if your problem is similar to this one? #26 (comment)

@migueleliasweb migueleliasweb added the bug Something isn't working label Apr 8, 2022
@oba11
Copy link
Author

oba11 commented Apr 8, 2022

@migueleliasweb yes you are right, I just tested https://github.com/migueleliasweb/go-github-mock@allow-extended-last-parameters and it works. Thanks alot

@migueleliasweb
Copy link
Owner

Closing in favour of #26

@oba11
Copy link
Author

oba11 commented Apr 18, 2022

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants