Skip to content

Commit

Permalink
update docs and add mocks pkg (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler authored Nov 9, 2023
1 parent 4a57125 commit ad5613c
Show file tree
Hide file tree
Showing 13 changed files with 593 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: fmt check-fmt lint vet test
.PHONY: fmt lint test mocks test_coverage

GO_PKGS := $(shell go list -f {{.Dir}} ./...)

Expand All @@ -15,3 +15,6 @@ test:
test_coverage:
@go test -race -v $(GO_FLAGS) -count=1 -coverprofile=coverage.out -covermode=atomic $(GO_PKGS)
@go tool cover -html coverage.out

mocks:
@go generate ./...
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ func main() {
Global job options can be set when creating a scheduler using `NewScheduler`.
- [**Scheduler options**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#SchedulerOption):
Scheduler options can be set when creating a scheduler using `NewScheduler`.
- **Logging**: Logs can be enabled.
- [Logger](https://pkg.go.dev/github.com/go-co-op/gocron/v2#Logger):
The Logger interface can be implemented with your desired logging library.
The provided NewLogger uses the standard library's log package.
- **Mocking**: The gocron library is set up to enable testing.
- Mocks are provided in [the mock package](mocks) using [gomock](https://github.com/uber-go/mock).
- Time can be mocked by passing in a [FakeClock](https://pkg.go.dev/github.com/jonboulle/clockwork#FakeClock)
to [WithClock](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithClock) -
see the example on WithClock in the go-docs.

## Supporters

Expand Down
1 change: 1 addition & 0 deletions distributed.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate mockgen -source=distributed.go -destination=mocks/distributed.go -package=gocronmocks
package gocron

import "context"
Expand Down
1 change: 1 addition & 0 deletions job.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate mockgen -source=job.go -destination=mocks/job.go -package=gocronmocks
package gocron

import (
Expand Down
1 change: 1 addition & 0 deletions logger.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate mockgen -source=logger.go -destination=mocks/logger.go -package=gocronmocks
package gocron

import (
Expand Down
35 changes: 35 additions & 0 deletions mocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# gocron mocks

## Quick Start

```
go get github.com/go-co-op/gocronmocks/v2
```

write a test
```golang
package main

import (
"testing"

"github.com/go-co-op/gocron/v2"
"github.com/go-co-op/gocronmocks/v2"
"go.uber.org/mock/gomock"
)

func myFunc(s gocron.Scheduler) {
s.Start()
_ = s.Shutdown()
}

func TestMyFunc(t *testing.T) {
ctrl := gomock.NewController(t)
s := gocronmocks.NewMockScheduler(ctrl)
s.EXPECT().Start().Times(1)
s.EXPECT().Shutdown().Times(1).Return(nil)

myFunc(s)
}

```
53 changes: 53 additions & 0 deletions mocks/distributed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions mocks/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/go-co-op/gocronmocks/v2

go 1.20

require (
github.com/go-co-op/gocron/v2 v2.0.0-rc1
github.com/google/uuid v1.4.0
go.uber.org/mock v0.3.0
)

require (
github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
)
17 changes: 17 additions & 0 deletions mocks/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/go-co-op/gocron/v2 v2.0.0-rc1 h1:qkj0WVO6uh6ibZa2CQ0Ifxk3A+c6rawZnIby94/5sAM=
github.com/go-co-op/gocron/v2 v2.0.0-rc1/go.mod h1:3SLoqKnyORFVN0VvFFb1383hM4WD9XHBPn9aUUp7sQs=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
186 changes: 186 additions & 0 deletions mocks/job.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ad5613c

Please sign in to comment.