ci: enable gofumt linter (#887)
Signed-off-by: Long Dai <long0dai@foxmail.com>
This commit is contained in:
parent
b387fcdff3
commit
4ee732e0bd
|
@ -228,5 +228,4 @@ linters:
|
|||
- godot
|
||||
- testpackage
|
||||
- goerr113
|
||||
- gofumpt
|
||||
- gci
|
||||
|
|
|
@ -58,12 +58,14 @@ func TestPublishMsg(t *testing.T) { //nolint:paralleltest
|
|||
func TestBindingReadAndInvoke(t *testing.T) { //nolint:paralleltest
|
||||
msg := "{\"type\": \"text\",\"text\": {\"content\": \"hello\"}}"
|
||||
|
||||
m := bindings.Metadata{Name: "test",
|
||||
m := bindings.Metadata{
|
||||
Name: "test",
|
||||
Properties: map[string]string{
|
||||
"url": "/test",
|
||||
"secret": "",
|
||||
"id": "x",
|
||||
}}
|
||||
},
|
||||
}
|
||||
|
||||
d := NewDingTalkWebhook(logger.NewLogger("test"))
|
||||
err := d.Init(m)
|
||||
|
|
|
@ -333,7 +333,7 @@ func convertConfigs(ss string) ([]configParam, error) {
|
|||
}
|
||||
|
||||
for _, s := range strings.Split(ss, ",") {
|
||||
var nacosConfigParam, err = convertConfig(s)
|
||||
nacosConfigParam, err := convertConfig(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ type mqCallback func(ctx context.Context, msgs ...*primitive.MessageExt) (mqc.Co
|
|||
|
||||
func (a *AliCloudRocketMQ) adaptCallback(_, consumerGroup, mqType, mqExpr string, handler func(*bindings.ReadResponse) ([]byte, error)) mqCallback {
|
||||
return func(ctx context.Context, msgs ...*primitive.MessageExt) (mqc.ConsumeResult, error) {
|
||||
var success = true
|
||||
success := true
|
||||
for _, v := range msgs {
|
||||
metadata := make(map[string]string, 4)
|
||||
metadata[metadataRocketmqType] = mqType
|
||||
|
@ -258,8 +258,10 @@ func (a *AliCloudRocketMQ) adaptCallback(_, consumerGroup, mqType, mqExpr string
|
|||
}
|
||||
a.logger.Debugf("binging-rocketmq handle msg, topic:%s msg-id:%s data-length:%d ", v.Topic, len(v.Body), v.MsgId)
|
||||
|
||||
msg := &bindings.ReadResponse{Data: v.Body,
|
||||
Metadata: metadata}
|
||||
msg := &bindings.ReadResponse{
|
||||
Data: v.Body,
|
||||
Metadata: metadata,
|
||||
}
|
||||
|
||||
b := a.backOffConfig.NewBackOffWithContext(a.ctx)
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ func TestInputBindingRead(t *testing.T) { //nolint:paralleltest
|
|||
|
||||
time.Sleep(5 * time.Second)
|
||||
atomic.StoreInt32(&count, 0)
|
||||
var req = &bindings.InvokeRequest{Data: []byte("hello"), Operation: bindings.CreateOperation, Metadata: map[string]string{}}
|
||||
req := &bindings.InvokeRequest{Data: []byte("hello"), Operation: bindings.CreateOperation, Metadata: map[string]string{}}
|
||||
_, err = r.Invoke(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ func (h *HTTPSource) Init(metadata bindings.Metadata) error {
|
|||
dialer := &net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
var netTransport = &http.Transport{
|
||||
netTransport := &http.Transport{
|
||||
Dial: dialer.Dial,
|
||||
TLSHandshakeTimeout: 5 * time.Second,
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@ import (
|
|||
|
||||
func TestOperations(t *testing.T) {
|
||||
opers := (*binding_http.HTTPSource)(nil).Operations()
|
||||
assert.Equal(t, []bindings.OperationKind{bindings.CreateOperation,
|
||||
assert.Equal(t, []bindings.OperationKind{
|
||||
bindings.CreateOperation,
|
||||
"get",
|
||||
"head",
|
||||
"post",
|
||||
|
@ -30,7 +31,8 @@ func TestOperations(t *testing.T) {
|
|||
"patch",
|
||||
"delete",
|
||||
"options",
|
||||
"trace"}, opers)
|
||||
"trace",
|
||||
}, opers)
|
||||
}
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
|
|
|
@ -254,7 +254,6 @@ func initDB(url, pemPath string) (*sql.DB, error) {
|
|||
if pemPath != "" {
|
||||
rootCertPool := x509.NewCertPool()
|
||||
pem, err := ioutil.ReadFile(pemPath)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Error reading PEM file from %s", pemPath)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ func TestParseMetadata(t *testing.T) {
|
|||
"emailTo": "to@dapr.io",
|
||||
"emailCC": "cc@dapr.io",
|
||||
"emailBCC": "bcc@dapr.io",
|
||||
"subject": "Test email"}
|
||||
"subject": "Test email",
|
||||
}
|
||||
r := Mailer{logger: logger}
|
||||
smtpMeta, err := r.parseMetadata(m)
|
||||
assert.Nil(t, err)
|
||||
|
@ -47,7 +48,7 @@ func TestParseMetadata(t *testing.T) {
|
|||
|
||||
func TestMergeWithRequestMetadata(t *testing.T) {
|
||||
t.Run("Has merged metadata", func(t *testing.T) {
|
||||
var smtpMeta = Metadata{
|
||||
smtpMeta := Metadata{
|
||||
Host: "mailserver.dapr.io",
|
||||
Port: 25,
|
||||
User: "user@dapr.io",
|
||||
|
@ -57,15 +58,17 @@ func TestMergeWithRequestMetadata(t *testing.T) {
|
|||
EmailTo: "to@dapr.io",
|
||||
EmailCC: "cc@dapr.io",
|
||||
EmailBCC: "bcc@dapr.io",
|
||||
Subject: "Test email"}
|
||||
Subject: "Test email",
|
||||
}
|
||||
|
||||
var request = bindings.InvokeRequest{}
|
||||
request := bindings.InvokeRequest{}
|
||||
request.Metadata = map[string]string{
|
||||
"emailFrom": "req-from@dapr.io",
|
||||
"emailTo": "req-to@dapr.io",
|
||||
"emailCC": "req-cc@dapr.io",
|
||||
"emailBCC": "req-bcc@dapr.io",
|
||||
"subject": "req-Test email"}
|
||||
"subject": "req-Test email",
|
||||
}
|
||||
|
||||
mergedMeta := smtpMeta.mergeWithRequestMetadata(&request)
|
||||
|
||||
|
@ -84,7 +87,7 @@ func TestMergeWithRequestMetadata(t *testing.T) {
|
|||
|
||||
func TestMergeWithNoRequestMetadata(t *testing.T) {
|
||||
t.Run("Has no merged metadata", func(t *testing.T) {
|
||||
var smtpMeta = Metadata{
|
||||
smtpMeta := Metadata{
|
||||
Host: "mailserver.dapr.io",
|
||||
Port: 25,
|
||||
User: "user@dapr.io",
|
||||
|
@ -94,9 +97,10 @@ func TestMergeWithNoRequestMetadata(t *testing.T) {
|
|||
EmailTo: "to@dapr.io",
|
||||
EmailCC: "cc@dapr.io",
|
||||
EmailBCC: "bcc@dapr.io",
|
||||
Subject: "Test email"}
|
||||
Subject: "Test email",
|
||||
}
|
||||
|
||||
var request = bindings.InvokeRequest{}
|
||||
request := bindings.InvokeRequest{}
|
||||
request.Metadata = map[string]string{}
|
||||
|
||||
mergedMeta := smtpMeta.mergeWithRequestMetadata(&request)
|
||||
|
|
|
@ -16,9 +16,7 @@ import (
|
|||
"github.com/dapr/kit/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrMissingGatewayAddr = errors.New("gatewayAddr is a required attribute")
|
||||
)
|
||||
var ErrMissingGatewayAddr = errors.New("gatewayAddr is a required attribute")
|
||||
|
||||
// ClientFactory enables injection for testing
|
||||
type ClientFactory interface {
|
||||
|
|
|
@ -20,7 +20,8 @@ func TestParseMetadata(t *testing.T) {
|
|||
"gatewayAddr": "172.0.0.1:1234",
|
||||
"gatewayKeepAlive": "5s",
|
||||
"caCertificatePath": "/cert/path",
|
||||
"usePlaintextConnection": "true"}}
|
||||
"usePlaintextConnection": "true",
|
||||
}}
|
||||
client := ClientFactoryImpl{logger: logger.NewLogger("test")}
|
||||
meta, err := client.parseMetadata(m)
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -14,9 +14,7 @@ import (
|
|||
"github.com/dapr/components-contrib/bindings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrMissingWorkflowInstanceKey = errors.New("workflowInstanceKey is a required attribute")
|
||||
)
|
||||
var ErrMissingWorkflowInstanceKey = errors.New("workflowInstanceKey is a required attribute")
|
||||
|
||||
type cancelInstancePayload struct {
|
||||
WorkflowInstanceKey *int64 `json:"workflowInstanceKey"`
|
||||
|
|
|
@ -42,7 +42,7 @@ func (z *ZeebeCommand) deployWorkflow(req *bindings.InvokeRequest) (*bindings.In
|
|||
if val, ok := req.Metadata[fileType]; ok && val != "" {
|
||||
deployFileType = val
|
||||
} else {
|
||||
var extension = filepath.Ext(deployFileName)
|
||||
extension := filepath.Ext(deployFileName)
|
||||
if extension == "" {
|
||||
return nil, ErrMissingFileType
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@ import (
|
|||
"github.com/dapr/components-contrib/bindings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrMissingRetries = errors.New("retries is a required attribute")
|
||||
)
|
||||
var ErrMissingRetries = errors.New("retries is a required attribute")
|
||||
|
||||
type failJobPayload struct {
|
||||
JobKey *int64 `json:"jobKey"`
|
||||
|
|
|
@ -16,9 +16,7 @@ import (
|
|||
"github.com/dapr/components-contrib/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrMissingMessageName = errors.New("messageName is a required attribute")
|
||||
)
|
||||
var ErrMissingMessageName = errors.New("messageName is a required attribute")
|
||||
|
||||
type publishMessagePayload struct {
|
||||
MessageName string `json:"messageName"`
|
||||
|
|
|
@ -14,9 +14,7 @@ import (
|
|||
"github.com/dapr/components-contrib/bindings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrMissingIncidentKey = errors.New("incidentKey is a required attribute")
|
||||
)
|
||||
var ErrMissingIncidentKey = errors.New("incidentKey is a required attribute")
|
||||
|
||||
type resolveIncidentPayload struct {
|
||||
IncidentKey *int64 `json:"incidentKey"`
|
||||
|
|
|
@ -14,9 +14,7 @@ import (
|
|||
"github.com/dapr/components-contrib/bindings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrMissingErrorCode = errors.New("errorCode is a required attribute")
|
||||
)
|
||||
var ErrMissingErrorCode = errors.New("errorCode is a required attribute")
|
||||
|
||||
type throwErrorPayload struct {
|
||||
JobKey *int64 `json:"jobKey"`
|
||||
|
|
|
@ -24,9 +24,7 @@ import (
|
|||
"github.com/dapr/kit/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrMissingJobType = errors.New("jobType is a required attribute")
|
||||
)
|
||||
var ErrMissingJobType = errors.New("jobType is a required attribute")
|
||||
|
||||
// ZeebeJobWorker allows handling jobs from the Zeebe command engine
|
||||
type ZeebeJobWorker struct {
|
||||
|
|
|
@ -71,7 +71,6 @@ func (m *Middleware) GetHandler(metadata middleware.Metadata) (func(h fasthttp.R
|
|||
sentinel.WithResourceType(base.ResTypeWeb),
|
||||
sentinel.WithTrafficType(base.Inbound),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
ctx.Error(fasthttp.StatusMessage(fasthttp.StatusTooManyRequests), fasthttp.StatusTooManyRequests)
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ func (r *resolver) Init(metadata nr.Metadata) error {
|
|||
func (r *resolver) ResolveID(req nr.ResolveRequest) (string, error) {
|
||||
cfg := r.config
|
||||
services, _, err := r.client.Health().Service(req.ID, "", true, cfg.QueryOptions)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to query healthy consul services: %w", err)
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
func(t *testing.T, req nr.ResolveRequest) {
|
||||
t.Helper()
|
||||
var mock = mockClient{
|
||||
mock := mockClient{
|
||||
mockHealth: mockHealth{
|
||||
serviceResult: []*consul.ServiceEntry{},
|
||||
},
|
||||
|
@ -185,7 +185,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
func(t *testing.T, req nr.ResolveRequest) {
|
||||
t.Helper()
|
||||
var mock = mockClient{
|
||||
mock := mockClient{
|
||||
mockHealth: mockHealth{
|
||||
serviceResult: []*consul.ServiceEntry{
|
||||
{
|
||||
|
@ -214,7 +214,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
func(t *testing.T, req nr.ResolveRequest) {
|
||||
t.Helper()
|
||||
var mock = mockClient{
|
||||
mock := mockClient{
|
||||
mockHealth: mockHealth{
|
||||
serviceResult: []*consul.ServiceEntry{
|
||||
{
|
||||
|
@ -258,7 +258,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
func(t *testing.T, req nr.ResolveRequest) {
|
||||
t.Helper()
|
||||
var mock = mockClient{
|
||||
mock := mockClient{
|
||||
mockHealth: mockHealth{
|
||||
serviceResult: []*consul.ServiceEntry{
|
||||
{
|
||||
|
@ -269,7 +269,8 @@ func TestResolveID(t *testing.T) {
|
|||
"DAPR_PORT": "50005",
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
resolver := newResolver(logger.NewLogger("test"), *testConfig, &mock)
|
||||
|
@ -286,7 +287,7 @@ func TestResolveID(t *testing.T) {
|
|||
},
|
||||
func(t *testing.T, req nr.ResolveRequest) {
|
||||
t.Helper()
|
||||
var mock = mockClient{
|
||||
mock := mockClient{
|
||||
mockHealth: mockHealth{
|
||||
serviceResult: []*consul.ServiceEntry{
|
||||
{
|
||||
|
|
|
@ -246,12 +246,11 @@ type mqCallback func(ctx context.Context, msgs ...*primitive.MessageExt) (mqc.Co
|
|||
|
||||
func (r *rocketMQ) adaptCallback(topic, consumerGroup, mqType, mqExpr string, handler pubsub.Handler) mqCallback {
|
||||
return func(ctx context.Context, msgs ...*primitive.MessageExt) (mqc.ConsumeResult, error) {
|
||||
var success = true
|
||||
success := true
|
||||
for _, v := range msgs {
|
||||
data := pubsub.NewCloudEventsEnvelope(v.MsgId, v.StoreHost, r.name,
|
||||
v.GetProperty(primitive.PropertyKeys), v.Topic, r.name, r.settings.ContentType, v.Body, "")
|
||||
dataBytes, err := r.json.Marshal(data)
|
||||
|
||||
if err != nil {
|
||||
r.logger.Warn("rocketmq fail to marshal data message, topic:%s data-length:%d err:%v ", v.Topic, len(v.Body), err)
|
||||
success = false
|
||||
|
|
|
@ -154,7 +154,7 @@ func (g *GCPPubSub) getPubSubClient(ctx context.Context, metadata *metadata) (*g
|
|||
var err error
|
||||
|
||||
if metadata.PrivateKeyID != "" {
|
||||
//TODO: validate that all auth json fields are filled
|
||||
// TODO: validate that all auth json fields are filled
|
||||
authJSON := &GCPAuthJSON{
|
||||
ProjectID: metadata.IdentityProjectID,
|
||||
PrivateKeyID: metadata.PrivateKeyID,
|
||||
|
|
|
@ -69,6 +69,7 @@ type TestConfiguration struct {
|
|||
ComponentType string `yaml:"componentType,omitempty"`
|
||||
Components []TestComponent `yaml:"components,omitempty"`
|
||||
}
|
||||
|
||||
type TestComponent struct {
|
||||
Component string `yaml:"component,omitempty"`
|
||||
Profile string `yaml:"profile,omitempty"`
|
||||
|
|
|
@ -51,7 +51,8 @@ func NewTestConfig(componentName string, allOperations bool, operations []string
|
|||
ComponentType: "pubsub",
|
||||
ComponentName: componentName,
|
||||
AllOperations: allOperations,
|
||||
Operations: utils.NewStringSet(operations...)},
|
||||
Operations: utils.NewStringSet(operations...),
|
||||
},
|
||||
PubsubName: defaultPubsubName,
|
||||
TestTopicName: defaultTopicName,
|
||||
MessageCount: defaultMessageCount,
|
||||
|
|
Loading…
Reference in New Issue