Skip to content
forked from 1Password/gitlab

go-gitlab wrapper that supports mocking

License

Notifications You must be signed in to change notification settings

jeveleth1p/gitlab

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitlab

Latest Version License GitHub Workflow Status Codecov

Wrapper for go-gitlab (gitlab.com/gitlab-org/api/client-go) that supports mocking.

Usage

See our Go docs 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:

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.

// 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:

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.

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

About

go-gitlab wrapper that supports mocking

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 94.5%
  • Smarty 3.9%
  • Shell 1.6%