https://github.com/jaredallard/gitlab
go-gitlab wrapper that supports mocking
https://github.com/jaredallard/gitlab
gitlab go golang golang-library
Last synced: 3 months ago
JSON representation
go-gitlab wrapper that supports mocking
- Host: GitHub
- URL: https://github.com/jaredallard/gitlab
- Owner: jaredallard
- License: lgpl-3.0
- Created: 2024-09-18T02:49:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-01T21:50:45.000Z (12 months ago)
- Last Synced: 2025-01-01T22:29:26.171Z (12 months ago)
- Topics: gitlab, go, golang, golang-library
- Language: Go
- Homepage:
- Size: 478 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Audit: auditeventsservice_inf.go
Awesome Lists containing this project
README
# gitlab
Wrapper for [go-gitlab]
([gitlab.com/gitlab-org/api/client-go](gitlab.com/gitlab-org/api/client-go))
that supports mocking.
## Usage
See our [Go docs](https://pkg.go.dev/github.com/1password/gitlab) as
well as the upstream [go-gitlab] documentation which this package
provides.
### Differences
Due to the original [go-gitlab] `Client` struct using embedded structs
instead of interfaces, you must use the `NewClient` call from this
package.
Example:
```go
gl, err := gitlab.NewClient()
if err != nil {
// handle err
}
// Original
gl.MergeRequests.GetMergeRequest()
// New
gl.MergeRequests().GetMergeRequest()
```
You will also need to dereference `gitlab.Client` as it is now and
interface instead of a struct.
```go
// Original
type MyStruct {
gl *gitlab.Client
}
// New
type MyStruct {
gl gitlab.Client
}
```
### Using the mocks
All of the mocks are generated via [mockgen] under the hood. You can
access them on the `MockClient` type.
Example:
```go
func TestCanGetMergeRequest(t *testing.T) {
gl := gitlab.NewMockClient(t)
// Should be called once w/ the given arguments and return the given
// result.
gl.MergeRequestsServiceMock.EXPECT().
GetMergeRequest(1, 1, &gitlab.GetMergeRequestsOptions{}).
Return(&gitlab.MergeRequest{
ID: 1,
}, nil, nil)
mr, _, err := gl.MergeRequests().GetMergeRequest(1, 1, &gitlab.GetMergeRequestsOptions{})
assert.NilError(t, err)
assert.Equal(t, mr.ID, 1)
}
```
## Development
All of the code in this repository is generated through the
`tools/codegen` CLI. To change anything, you must add it to that CLI
tool.
The templates used can be found in the `embed` directory in the same CLI
directory.
When you bump dependency versions — specifically, the client-go package — be
sure to run `mise generate` to pull in the latest changes to the package.
## Special Thanks
Huge special thanks to the [mockgen] and [ifacemaker] project for making
this possible and saving me a lot of pain w/ the ast package :)
## License
LGPL-3.0
[go-gitlab]: gitlab.com/gitlab-org/api/client-go
[mockgen]: https://pkg.go.dev/go.uber.org/mock/mockgen
[ifacemaker]: https://github.com/vburenin/ifacemaker@latest