mirror of
https://github.com/thegeeklab/wp-matrix.git
synced 2024-06-02 18:39:40 +02:00
cleanup
This commit is contained in:
parent
fb869ec38a
commit
f4e5bf0d13
6
.mockery.yaml
Normal file
6
.mockery.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
all: True
|
||||
dir: mocks
|
||||
outpkg: "mocks"
|
||||
packages:
|
||||
github.com/thegeeklab/wp-matrix/plugin:
|
9
Makefile
9
Makefile
|
@ -11,7 +11,7 @@ IMPORT := github.com/thegeeklab/$(EXECUTABLE)
|
|||
|
||||
GO ?= go
|
||||
CWD ?= $(shell pwd)
|
||||
PACKAGES ?= $(shell go list ./...)
|
||||
PACKAGES ?= $(shell go list ./... | grep -Ev 'mocks')
|
||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||
|
||||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
||||
|
@ -19,7 +19,6 @@ GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(G
|
|||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
||||
|
||||
GENERATE ?=
|
||||
XGO_VERSION := go-1.22.x
|
||||
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
|
||||
|
||||
|
@ -65,11 +64,7 @@ lint: golangci-lint
|
|||
|
||||
.PHONY: generate
|
||||
generate:
|
||||
$(GO) generate $(GENERATE)
|
||||
|
||||
.PHONY: generate-docs
|
||||
generate-docs:
|
||||
$(GO) generate ./cmd/$(EXECUTABLE)/flags.go
|
||||
$(GO) generate $(PACKAGES)
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
|
|
|
@ -13,6 +13,20 @@ properties:
|
|||
defaultValue: "https://matrix.org"
|
||||
required: false
|
||||
|
||||
- name: insecure_skip_verify
|
||||
description: |
|
||||
Skip SSL verification.
|
||||
type: bool
|
||||
defaultValue: false
|
||||
required: false
|
||||
|
||||
- name: log_level
|
||||
description: |
|
||||
Plugin log level.
|
||||
type: string
|
||||
defaultValue: "info"
|
||||
required: false
|
||||
|
||||
- name: password
|
||||
description: |
|
||||
Authentication password.
|
||||
|
|
|
@ -11,8 +11,6 @@ import (
|
|||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
//go:generate mockery --name=MautrixClient --output=mocks --case=underscore
|
||||
|
||||
//nolint:lll
|
||||
type MautrixClient interface {
|
||||
SendMessageEvent(ctx context.Context, roomID id.RoomID, eventType event.Type, contentJSON interface{}, extra ...mautrix.ReqSendEvent) (resp *mautrix.RespSendEvent, err error)
|
||||
|
|
|
@ -89,7 +89,7 @@ func TestMatrixMessageSend(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockClient := mocks.NewMautrixClient(t)
|
||||
mockClient := mocks.NewMockMautrixClient(t)
|
||||
m := &MatrixMessage{
|
||||
Opt: tt.messageOpt,
|
||||
client: mockClient,
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
// Code generated by mockery v2.42.1. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
event "maunium.net/go/mautrix/event"
|
||||
id "maunium.net/go/mautrix/id"
|
||||
|
||||
mautrix "maunium.net/go/mautrix"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// MautrixClient is an autogenerated mock type for the MautrixClient type
|
||||
type MautrixClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// SendMessageEvent provides a mock function with given fields: ctx, roomID, eventType, contentJSON, extra
|
||||
func (_m *MautrixClient) SendMessageEvent(ctx context.Context, roomID id.RoomID, eventType event.Type, contentJSON interface{}, extra ...mautrix.ReqSendEvent) (*mautrix.RespSendEvent, error) {
|
||||
_va := make([]interface{}, len(extra))
|
||||
for _i := range extra {
|
||||
_va[_i] = extra[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, roomID, eventType, contentJSON)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for SendMessageEvent")
|
||||
}
|
||||
|
||||
var r0 *mautrix.RespSendEvent
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, id.RoomID, event.Type, interface{}, ...mautrix.ReqSendEvent) (*mautrix.RespSendEvent, error)); ok {
|
||||
return rf(ctx, roomID, eventType, contentJSON, extra...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, id.RoomID, event.Type, interface{}, ...mautrix.ReqSendEvent) *mautrix.RespSendEvent); ok {
|
||||
r0 = rf(ctx, roomID, eventType, contentJSON, extra...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*mautrix.RespSendEvent)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, id.RoomID, event.Type, interface{}, ...mautrix.ReqSendEvent) error); ok {
|
||||
r1 = rf(ctx, roomID, eventType, contentJSON, extra...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// NewMautrixClient creates a new instance of MautrixClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMautrixClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *MautrixClient {
|
||||
mock := &MautrixClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
117
plugin/mocks/mock_MautrixClient.go
Normal file
117
plugin/mocks/mock_MautrixClient.go
Normal file
|
@ -0,0 +1,117 @@
|
|||
// Code generated by mockery v2.42.1. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
event "maunium.net/go/mautrix/event"
|
||||
id "maunium.net/go/mautrix/id"
|
||||
|
||||
mautrix "maunium.net/go/mautrix"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// MockMautrixClient is an autogenerated mock type for the MautrixClient type
|
||||
type MockMautrixClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type MockMautrixClient_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *MockMautrixClient) EXPECT() *MockMautrixClient_Expecter {
|
||||
return &MockMautrixClient_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// SendMessageEvent provides a mock function with given fields: ctx, roomID, eventType, contentJSON, extra
|
||||
func (_m *MockMautrixClient) SendMessageEvent(ctx context.Context, roomID id.RoomID, eventType event.Type, contentJSON interface{}, extra ...mautrix.ReqSendEvent) (*mautrix.RespSendEvent, error) {
|
||||
_va := make([]interface{}, len(extra))
|
||||
for _i := range extra {
|
||||
_va[_i] = extra[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, roomID, eventType, contentJSON)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for SendMessageEvent")
|
||||
}
|
||||
|
||||
var r0 *mautrix.RespSendEvent
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, id.RoomID, event.Type, interface{}, ...mautrix.ReqSendEvent) (*mautrix.RespSendEvent, error)); ok {
|
||||
return rf(ctx, roomID, eventType, contentJSON, extra...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, id.RoomID, event.Type, interface{}, ...mautrix.ReqSendEvent) *mautrix.RespSendEvent); ok {
|
||||
r0 = rf(ctx, roomID, eventType, contentJSON, extra...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*mautrix.RespSendEvent)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, id.RoomID, event.Type, interface{}, ...mautrix.ReqSendEvent) error); ok {
|
||||
r1 = rf(ctx, roomID, eventType, contentJSON, extra...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockMautrixClient_SendMessageEvent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendMessageEvent'
|
||||
type MockMautrixClient_SendMessageEvent_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// SendMessageEvent is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - roomID id.RoomID
|
||||
// - eventType event.Type
|
||||
// - contentJSON interface{}
|
||||
// - extra ...mautrix.ReqSendEvent
|
||||
func (_e *MockMautrixClient_Expecter) SendMessageEvent(ctx interface{}, roomID interface{}, eventType interface{}, contentJSON interface{}, extra ...interface{}) *MockMautrixClient_SendMessageEvent_Call {
|
||||
return &MockMautrixClient_SendMessageEvent_Call{Call: _e.mock.On("SendMessageEvent",
|
||||
append([]interface{}{ctx, roomID, eventType, contentJSON}, extra...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockMautrixClient_SendMessageEvent_Call) Run(run func(ctx context.Context, roomID id.RoomID, eventType event.Type, contentJSON interface{}, extra ...mautrix.ReqSendEvent)) *MockMautrixClient_SendMessageEvent_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]mautrix.ReqSendEvent, len(args)-4)
|
||||
for i, a := range args[4:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(mautrix.ReqSendEvent)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(id.RoomID), args[2].(event.Type), args[3].(interface{}), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockMautrixClient_SendMessageEvent_Call) Return(resp *mautrix.RespSendEvent, err error) *MockMautrixClient_SendMessageEvent_Call {
|
||||
_c.Call.Return(resp, err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockMautrixClient_SendMessageEvent_Call) RunAndReturn(run func(context.Context, id.RoomID, event.Type, interface{}, ...mautrix.ReqSendEvent) (*mautrix.RespSendEvent, error)) *MockMautrixClient_SendMessageEvent_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewMockMautrixClient creates a new instance of MockMautrixClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockMautrixClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *MockMautrixClient {
|
||||
mock := &MockMautrixClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
|
@ -13,6 +13,9 @@ import (
|
|||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
//go:generate mockery
|
||||
//go:generate go run ../internal/doc/main.go -output=../docs/data/data-raw.yaml
|
||||
|
||||
//nolint:lll
|
||||
const DefaultMessageTemplate = `
|
||||
Status: **{{ .Pipeline.Status }}**
|
||||
|
|
Loading…
Reference in New Issue
Block a user