Closed kalgurn closed 2 years ago
Hi @kalgurn , see if this example works for you. I just had to adapt a couple of things:
mockedHTTPClient := NewMockedHTTPClient(
WithRequestMatch(
GetRateLimit,
struct {
Resources *github.RateLimits
}{
Resources: &github.RateLimits{
Core: &github.Rate{
Limit: *github.Int(1),
Remaining: 10,
Reset: github.Timestamp{},
},
Search: &github.Rate{},
},
},
),
)
c := github.NewClient(mockedHTTPClient)
ctx := context.Background()
limits, response, err := c.RateLimits(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(response, limits, err)
For some reason, the upstream response for the rate limits endpoints doesn't seem to match what is defined in the OpenAPI definition for the API itself. Even go-github
seems to hack a struct when reading the response from the API. See: https://github.com/google/go-github/blob/master/github/github.go#L1107
It actually does, thank you @migueleliasweb ! I did noticed this line before, but didn't give a much thought to it :( The response is a bit strange,
github.Response: github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}
github.RateLimits: github.RateLimits{Core:github.Rate{Limit:1, Remaining:10, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, Search:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}}
err: <nil>
but I don't actually care about the github.Response
, only about github.RateLimits
which are now working.
I think this issue can be closed
I am trying to mock the request which should return an amount of remaining requests
For some reason my output looks like this
I was trying to return just a
github.Rate
,github.RateLimits
. I've swapped values withgithub.Int
. Still nothing. Use ofWithRequestMatchHandler
also did nothing. Am I missing something? Other requests I was trying to mock are working as expected and returns proper values.