diff options
| -rw-r--r-- | Taskfile.yml | 10 | ||||
| -rw-r--r-- | go.mod | 8 | ||||
| -rw-r--r-- | go.sum | 12 | ||||
| -rw-r--r-- | pkg/discord/mocks/event_handler.go | 24 | ||||
| -rw-r--r-- | pkg/discord/mocks/gateway.go | 56 | ||||
| -rw-r--r-- | pkg/discord/mocks/heartbeat.go | 31 | ||||
| -rw-r--r-- | pkg/discord/mocks/rest.go | 49 |
7 files changed, 190 insertions, 0 deletions
diff --git a/Taskfile.yml b/Taskfile.yml index c8c7960..9c3e6d3 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -13,3 +13,13 @@ tasks: deps: [build] cmds: - build/bot + + test: + desc: "Tests all packages." + cmds: + - go test ./... -timeout=1s + + generate-mocks: + desc: "Generates mocks for given pkg/." + cmds: + - mockery --all --case snake --srcpkg jinx/pkg/{{.CLI_ARGS}} --output pkg/{{.CLI_ARGS}}/mocks diff --git a/go.mod b/go.mod index e4906d7..6ceb103 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,12 @@ go 1.18 require ( github.com/gorilla/websocket v1.5.0 github.com/rs/zerolog v1.26.1 + github.com/stretchr/testify v1.7.1 +) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/objx v0.1.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect ) diff --git a/go.sum b/go.sum index 5532888..e635488 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,19 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc= github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -32,3 +40,7 @@ golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/discord/mocks/event_handler.go b/pkg/discord/mocks/event_handler.go new file mode 100644 index 0000000..f398722 --- /dev/null +++ b/pkg/discord/mocks/event_handler.go @@ -0,0 +1,24 @@ +// Code generated by mockery v2.10.4. DO NOT EDIT. + +package mocks + +import ( + events "jinx/pkg/discord/events" + + mock "github.com/stretchr/testify/mock" +) + +// EventHandler is an autogenerated mock type for the EventHandler type +type EventHandler struct { + mock.Mock +} + +// Add provides a mock function with given fields: event, handler +func (_m *EventHandler) Add(event events.Event, handler func(interface{})) { + _m.Called(event, handler) +} + +// Fire provides a mock function with given fields: event, payload +func (_m *EventHandler) Fire(event events.Event, payload interface{}) { + _m.Called(event, payload) +} diff --git a/pkg/discord/mocks/gateway.go b/pkg/discord/mocks/gateway.go new file mode 100644 index 0000000..1203897 --- /dev/null +++ b/pkg/discord/mocks/gateway.go @@ -0,0 +1,56 @@ +// Code generated by mockery v2.10.4. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// Gateway is an autogenerated mock type for the Gateway type +type Gateway struct { + mock.Mock +} + +// Close provides a mock function with given fields: +func (_m *Gateway) Close() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Heartbeat provides a mock function with given fields: +func (_m *Gateway) Heartbeat() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Start provides a mock function with given fields: ctx, url, token +func (_m *Gateway) Start(ctx context.Context, url string, token string) error { + ret := _m.Called(ctx, url, token) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, url, token) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/pkg/discord/mocks/heartbeat.go b/pkg/discord/mocks/heartbeat.go new file mode 100644 index 0000000..cf028cf --- /dev/null +++ b/pkg/discord/mocks/heartbeat.go @@ -0,0 +1,31 @@ +// Code generated by mockery v2.10.4. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + time "time" +) + +// Heartbeat is an autogenerated mock type for the Heartbeat type +type Heartbeat struct { + mock.Mock +} + +// Ack provides a mock function with given fields: +func (_m *Heartbeat) Ack() { + _m.Called() +} + +// ForceHeartbeat provides a mock function with given fields: +func (_m *Heartbeat) ForceHeartbeat() { + _m.Called() +} + +// Start provides a mock function with given fields: ctx, interval +func (_m *Heartbeat) Start(ctx context.Context, interval time.Duration) { + _m.Called(ctx, interval) +} diff --git a/pkg/discord/mocks/rest.go b/pkg/discord/mocks/rest.go new file mode 100644 index 0000000..92d45f1 --- /dev/null +++ b/pkg/discord/mocks/rest.go @@ -0,0 +1,49 @@ +// Code generated by mockery v2.10.4. DO NOT EDIT. + +package mocks + +import ( + entities "jinx/pkg/discord/entities" + + mock "github.com/stretchr/testify/mock" +) + +// REST is an autogenerated mock type for the REST type +type REST struct { + mock.Mock +} + +// Gateway provides a mock function with given fields: +func (_m *REST) Gateway() (string, error) { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SendMessage provides a mock function with given fields: channelID, content +func (_m *REST) SendMessage(channelID entities.Snowflake, content string) error { + ret := _m.Called(channelID, content) + + var r0 error + if rf, ok := ret.Get(0).(func(entities.Snowflake, string) error); ok { + r0 = rf(channelID, content) + } else { + r0 = ret.Error(0) + } + + return r0 +} |
