migueleliasweb / go-github-mock

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

Repositories.GetCommitSHA1 doesn't work as expected #39

Closed liranelisha closed 1 year ago

liranelisha commented 1 year ago

I'm starting to use this awesome mock package, and doing some tests on the different endpoints I've notices that i can mock client.Repositories.GetCommitSHA1 using the GetReposCommitsByOwnerByRepoByRef. At first it worked great, but once i've started to send more complex ref it fell apart. for example

sha, resp, err := ghClient.Repositories.GetCommitSHA1(context.Background(), "gg", "mocked-repo-2", "refs/heads/ddd", "") panics out. this is due to the /heads/ddd is added to the endpoint, and so i'm guessing is not get picked up by the mock implementation.... currently i've manually added

mockSha := mock.EndpointPattern{
  Pattern: "/repos/{owner}/{repo}/commits/{ref}/heads/{x}",
  Method:  "GET",
}

but it could be nice if the mock package can solve this

migueleliasweb commented 1 year ago

Hi @liranelisha ,

I think I know what the problem is. It should be an easy fix.

Let me check a couple of things.

Possibly related to last parameters having a forward slash like in: https://github.com/migueleliasweb/go-github-mock/issues/26

migueleliasweb commented 1 year ago

Hi @liranelisha , I've found the problem.

It was due to the way GH matches request params in the URL. It was a smal change as I knew these edge cases would happen.

I'm just finishing implementing some unittests.

migueleliasweb commented 1 year ago

@liranelisha Could you try to use this branch to see if it fixes your problem? https://github.com/migueleliasweb/go-github-mock/pull/40

The real change was: https://github.com/migueleliasweb/go-github-mock/pull/40/files#diff-de3bdf480ea16b407da4a65310f90bc74c077b9f15f2cfcb54d509c1d65cb894R13

liranelisha commented 1 year ago

pass with flying colors :) image

migueleliasweb commented 1 year ago

Cool, I will create a new release :+1: