32 Commits
Author SHA1 Message Date
Ajay Kemparaj f9fec07de4 feat: Require Go 1.26 and use new(expr) for pointer literals (#4481) 2026-08-28 12:18:49 -04:00
Oleksandr Redko 531d1cfb59 test: Fix test names and error messages (#4284) 2026-06-05 11:02:34 -04:00
Oleksandr Redko e4ea9e72c1 test: Use testJSONBody helper for request body assertions (#4283) 2026-06-05 09:27:14 -04:00
Oleksandr Redko 3215e0320e test: Remove redundant Marshal tests (#4266) 2026-06-04 09:22:07 -04:00
Oleksandr Redko d472d0844b fix: Use value receiver for MarshalJSON (#4211) 2026-05-14 17:16:06 -04:00
Oleksandr Redko 5158bb8e5f chore: Improve testJSONMarshal (#4042) 2026-02-27 07:27:18 -05:00
Glenn Lewis 4505771989 Prefer %v over %d,%s and add fmtpercentv custom linter (#3756) 2025-10-05 21:39:53 -04:00
Oleksandr Redko 233fe03e17 test: Use t.Context() instead of context.Background() (#3750) 2025-10-03 08:09:47 -04:00
Oleksandr Redko 3c5408e78f chore: Use any instead of interface{} (#3584) 2025-06-03 09:33:46 -04:00
Oleksandr Redko f66ed85955 feat: Deprecate and replace Bool,Int,Int64,String with Ptr using generics (#3355) 2024-12-10 21:36:09 -05:00
Glenn Lewis dc884c26ca Add t.Parallel to unit tests (#3297) 2024-10-05 07:29:05 -04:00
Glenn Lewis e56d378b96 refactor: Do not call teardown manually in tests (#3296) 2024-10-01 11:52:30 -04:00
Austin Vazquez 959861361f Remove references to io/ioutil package (#2547) 2022-11-07 08:41:12 -08:00
Sagar Sonwane b5eadeb0d5 Add test cases for JSON resource marshaling (#1972) 2021-07-13 13:13:52 -04:00
Sagar Sonwane 51e7595f87 fix: Updated comparisons in test files (#1875)
Replaced all reflect.DeepEqual comparisons in test files with cmp.Equal.

Fixes: #1851
2021-05-26 11:49:24 -07:00
Glenn Lewis 4489191f88 Add missing unit test (#1765) 2020-12-25 20:19:56 -05:00
Glenn Lewis 6e32c1e3c6 Improve git_trees.go coverage (#1741) 2020-12-25 18:54:50 -05:00
Glenn Lewis 460db534b8 Refactor context.Background in tests (#1672) 2020-12-16 05:58:28 -05:00
Glenn Lewis e4b511744f Add pointers to structs in slices (#1443) 2020-02-28 09:37:37 -05:00
Glenn Lewis ab35a4779b Implement file deletion for CreateTree (#1372) 2020-01-10 07:31:30 -05:00
Willem D'Haeseleer f6e074d7fd Support delete files for CreateTree (#1310)
Fixes #1268.
2019-12-05 07:51:24 -05:00
Nick Miyake 24b7e97643 Add Truncated field to Tree (#923)
Fixes #922.
2018-07-31 21:04:16 -04:00
Sahil Dua 922ceac058 tests: make use of testMethod consistent (#832)
Use testMethod to test the request method instead of manually comparing
it and testing. This change is to make things consistent through out the
code base.

Fixes #829.
2018-01-16 14:59:09 -08:00
Chris King df88dd9538 Remove global test variables in favor of local. (#766)
This refactor removes the global test variables used by all tests,
replacing them with local variables that are independent in each test.

This is better style, easier to read and be confident about correctness,
and allows tests to be parallelized in the future.

Resolves #762.
2017-12-02 14:34:41 -05:00
Yusuke Nemoto c03cf19687 Add TreeEntry.URL field (#632)
Resolves #629.
2017-05-06 17:07:02 -07:00
Dmitri Shuralyov 23d6cb9cac Add support for context package to all endpoints. (#529)
This is a large breaking API change. It is unavoidable and necessary
to resolve #526. This breaking change is part of bump to libraryVersion 3.

It adds ctx context.Context as first parameter to all endpoint methods,
including Do.

Updating for this API change should be easy and the compiler will help
catch instances that need to be updated. For example:

	main.go:193: not enough arguments in call to gh.Activity.MarkRepositoryNotificationsRead
		have (string, string, time.Time)
		want (context.Context, string, string, time.Time)
	...

You should pass the available context as first parameter. If your code
does not have context.Context available and you want to maintain previous
normal behavior, use context.Background(). Don't pass nil context; use
context.TODO() instead if you wish to delay figuring out the best context
to use. Then you can address the TODO at a later time.

Refer to documentation of package context at https://godoc.org/context
for more information.

This commit also changes ./tests/fields to use context.Background()
instead of deprecated oauth2.NoContext.

Resolves #526.
2017-02-20 16:05:42 -05:00
Tobias Schmidt 7b3c9bc76a Add support for "content" attribute at tree creation
The GitHub API supports a "content" attribute when creating a new tree
[1], which allows to skip additional requests to create blobs first.

[1]: https://developer.github.com/v3/git/trees/#create-a-tree
2014-06-11 20:58:15 -04:00
Will Norris a6715a27a0 code style cleanup
run through 'gofmt -s'
2013-09-13 08:20:30 -07:00
Will Norris 0392f18ad8 add tests for URL parse errors
These tests exercise the code path in all of our API methods where an
error is returned from github.NewRequest().  There are actually only two
ways to trigger an error here:
 - provide a URL which can't be parsed
 - provide a request body which can't be JSON encoded

In theory, it's also possible that http.NewRequest() could return an
error which would make its way up the stack, but in practice this will
never happen.  That's because http.NewRequest(), as currently
implemented, will only ever return an error if it's unable to parse the
provided URL.  But since we're simply passing the output of
URL.String(), we know that it will never be unparseable.  That leaves
the two options above.

For methods that don't have a request body (which is to say, most), all
we can do is force a URL parse error, which is most easily accomplished
by putting an unescaped "%" in the URL path.  This works for methods
that take a string input parameter that is directly added to the path.
If there are no string parameters to the function, or if they're not
part of the URL path, then we're mostly out of luck.  In some of those
cases, we can still try to force a JSON encoding error, but otherwise
there will be no way to exercise this code path in those methods.

Of course in this case, the fact that we can't test the error case means
that the error case isn't actually possible.  Nevertheless, I don't want
to ignore the error entirely in case some future change in the
implementation of github.NewRequest() or http.NewRequest() might
introduce a new possibility for erroring out.

What we're testing here is not likely to be a common error case, and
adding all of these tests to check for it in each method may be a bit
OCD, but I'd rather have the test coverage.
2013-08-22 15:51:54 -07:00
Will Norris 3072d069f2 switch singular GitHub struct fields to pointers
Like a51d6b4303, this change makes me sad, mainly because it is a
breaking change for all clients, and makes common tasks like reading
data out of structs slightly more work, with no direct benefit. Notably,
developers will need to make sure and check for nil values before trying
to dereference these pointers.  Sadly, the change is still necessary, as
is more fully explained in issue #19.  We can make the nil pointer
checks a little easier by adding some Get* funcs like goprotobuf does.

I spent a lot of time over the last few weeks exploring this change
(switching fields to pointers) versus the much larger change of using
protocol buffers for all GitHub data types.  While the goprotobuf
library is very mature and feature-rich (it's used heavily inside of
Google), it's the wrong tool for this task, since we're not actually
using the proto wire format.  While it does address the immediate
concern in #19, it makes way too many other things terribly awkward.

One of the biggest drawbacks of this change is that it will make the
string output from fmt.Printf("%v") next to useless, since all pointer
values are displayed as their memory address.  To handle that, I'll be
writing a custom String() function for these structs that is heavily
inspired by goprotobuf and internals from go's fmt package.
2013-08-20 13:21:47 -07:00
Will Norris a51d6b4303 return Response object from all API functions
The truth is, this change makes me sad.  It's a breaking change
for all clients and it adds more complexity to the library surface.  In
most cases, clients will simply drop the Response object on the floor
(which is actually all the library itself was doing before this
change... now we're just pushing that off to the client).

Initially, the Response object will be primarily of interest for
functions that return paginated result sets, since the Response.NextPage
field is the only way to know for sure if there are more pages that
should be fetched.  And this is really the cleanest way to get at that
data, so in that respect this change isn't so bad.

It's also worth noting that returning the raw Response object makes a
lot more since in a GitHub library than it may in others, given how
GitHub makes liberal (read: proper) use of HTTP request and response
headers.  Other APIs, like Google's various APIs for example, tend to
push things like pagination links into the response body.  While this is
certainly less of a purist view in terms of REST, it does make the lives
of client developers a lot easier, since then the response body contains
everything you need to know.  But whatever; this is how GitHub rolls, so
we'll roll right along with them.  (Somewhat ironically we are ignoring
the RESTful links in the GitHub response bodies, since we're actually
calling the API in an RPC style and don't do anything with those links.)

We still don't have an easy way to set arbitrary request headers, but
that's a problem for another day.

Fixes #22
2013-08-01 14:31:55 -07:00
Billy Lynch 1e532bd48b Restructured Git Data Service files. 2013-08-01 11:19:58 -04:00