Repository: vanus-labs/vanus
Pull request #509 (2023-03-09 14:04:02)

fix: fix ut and golint
### What problem does this PR solve?

Issue Number: close #xxx

### Problem Summary

### What is changed and how does it work?

### Check List

<!-- At least one of them must be included. -->

#### Tests

- [ ] Unit test
- [ ] Integration test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No code



Patch:
diff --git a/internal/primitive/config.go b/internal/primitive/config.go
index 2f846bc..1bf2fd7 100644
--- a/internal/primitive/config.go
+++ b/internal/primitive/config.go
@@ -15,7 +15,6 @@
 package primitive
 
 import (
-	"io/ioutil"
 	"os"
 
 	"gopkg.in/yaml.v3"
@@ -27,7 +26,7 @@ type KvStorageConfig struct {
 }
 
 func LoadConfig(filename string, config interface{}) error {
-	b, err := ioutil.ReadFile(filename)
+	b, err := os.ReadFile(filename)
 	if err != nil {
 		return err
 	}
diff --git a/internal/trigger/filter/prefix_filter.go b/internal/trigger/filter/prefix_filter.go
index b305f58..57a28cb 100644
--- a/internal/trigger/filter/prefix_filter.go
+++ b/internal/trigger/filter/prefix_filter.go
@@ -23,9 +23,7 @@ type prefixFilter struct {
 }
 
 func NewPrefixFilter(prefix map[string]string) Filter {
-	f := newCommonFilter(prefix, func(value, compareValue string) bool {
-		return strings.HasPrefix(value, compareValue)
-	})
+	f := newCommonFilter(prefix, strings.HasPrefix)
 	if f == nil {
 		return nil
 	}
diff --git a/internal/trigger/filter/suffix_filter.go b/internal/trigger/filter/suffix_filter.go
index 64f8ebc..87a6610 100644
--- a/internal/trigger/filter/suffix_filter.go
+++ b/internal/trigger/filter/suffix_filter.go
@@ -23,9 +23,7 @@ type suffixFilter struct {
 }
 
 func NewSuffixFilter(suffix map[string]string) Filter {
-	f := newCommonFilter(suffix, func(value, compareValue string) bool {
-		return strings.HasSuffix(value, compareValue)
-	})
+	f := newCommonFilter(suffix, strings.HasSuffix)
 	if f == nil {
 		return nil
 	}


Test patch:
diff --git a/internal/timer/timingwheel/bucket_test.go b/internal/timer/timingwheel/bucket_test.go
index 05fba24..75b9770 100644
--- a/internal/timer/timingwheel/bucket_test.go
+++ b/internal/timer/timingwheel/bucket_test.go
@@ -31,6 +31,7 @@ import (
 	"github.com/vanus-labs/vanus/pkg/errors"
 	"github.com/vanus-labs/vanus/proto/pkg/cloudevents"
 	"github.com/vanus-labs/vanus/proto/pkg/codec"
+	"github.com/vanus-labs/vanus/proto/pkg/meta"
 
 	"github.com/vanus-labs/vanus/internal/kv"
 )
@@ -259,7 +260,7 @@ func TestBucket_createEventbus(t *testing.T) {
 		tw.ctrl = mockCl
 		mockSvc := cluster.NewMockEventbusService(mockCtrl)
 		mockCl.EXPECT().EventbusService().Times(1).Return(mockSvc)
-		mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(nil)
+		mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(nil, nil)
 
 		err := bucket.createEventbus(ctx)
 		So(err, ShouldBeNil)
@@ -519,7 +520,10 @@ func TestBucket_recycle(t *testing.T) {
 		mockCl := cluster.NewMockCluster(mockCtrl)
 		tw.ctrl = mockCl
 		mockSvc := cluster.NewMockEventbusService(mockCtrl)
-		mockCl.EXPECT().EventbusService().Times(1).Return(mockSvc)
+		mockCl.EXPECT().EventbusService().AnyTimes().Return(mockSvc)
+		mockSvc.EXPECT().GetSystemEventbusByName(Any(), Any()).Times(1).Return(&meta.Eventbus{
+			Id: 0,
+		}, nil)
 		mockSvc.EXPECT().Delete(Any(), Any()).Times(1).Return(nil)
 
 		Convey("test bucket wait success", func() {
diff --git a/internal/timer/timingwheel/timingwheel_test.go b/internal/timer/timingwheel/timingwheel_test.go
index 4df0f43..2b1e325 100644
--- a/internal/timer/timingwheel/timingwheel_test.go
+++ b/internal/timer/timingwheel/timingwheel_test.go
@@ -34,6 +34,7 @@ import (
 	"github.com/vanus-labs/vanus/pkg/cluster"
 	"github.com/vanus-labs/vanus/pkg/errors"
 	ctrlpb "github.com/vanus-labs/vanus/proto/pkg/controller"
+	"github.com/vanus-labs/vanus/proto/pkg/meta"
 
 	"github.com/vanus-labs/vanus/internal/kv"
 	"github.com/vanus-labs/vanus/internal/timer/metadata"
@@ -88,7 +89,10 @@ func TestTimingWheel_Start(t *testing.T) {
 		tw.ctrl = mockCl
 		mockSvc := cluster.NewMockEventbusService(mockCtrl)
 		mockCl.EXPECT().EventbusService().AnyTimes().Return(mockSvc)
-		mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).AnyTimes().Return(nil)
+		mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).AnyTimes().Return(nil, nil)
+		mockSvc.EXPECT().GetSystemEventbusByName(Any(), Any()).AnyTimes().Return(&meta.Eventbus{
+			Id: 0,
+		}, nil)
 		mockSvc.EXPECT().IsExist(Any(), Any()).AnyTimes().Return(true)
 
 		Convey("test timingwheel start bucket start success", func() {
@@ -157,6 +161,9 @@ func TestTimingWheel_IsDeployed(t *testing.T) {
 		mockSvc := cluster.NewMockEventbusService(mockCtrl)
 		mockCl.EXPECT().EventbusService().AnyTimes().Return(mockSvc)
 		mockSvc.EXPECT().IsExist(Any(), Any()).AnyTimes().Return(true)
+		mockSvc.EXPECT().GetSystemEventbusByName(Any(), Any()).AnyTimes().Return(&meta.Eventbus{
+			Id: 0,
+		}, nil)
 
 		Convey("test timingwheel is deployed", func() {
 			ret := tw.IsDeployed(ctx)
@@ -267,7 +274,7 @@ func TestTimingWheel_startReceivingStation(t *testing.T) {
 		mockCl.EXPECT().EventbusService().AnyTimes().Return(mockSvc)
 
 		Convey("test timingwheel start receiving station with create eventbus failed", func() {
-			mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(errors.New("test"))
+			mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(nil, errors.New("test"))
 			err := tw.startReceivingStation(ctx)
 			So(err, ShouldNotBeNil)
 		})
@@ -372,7 +379,7 @@ func TestTimingWheel_startDistributionStation(t *testing.T) {
 		mockCl.EXPECT().EventbusService().AnyTimes().Return(mockSvc)
 
 		Convey("test timingwheel start distribution station with create eventbus failed", func() {
-			mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(errors.New("test"))
+			mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(nil, errors.New("test"))
 			err := tw.startDistributionStation(ctx)
 			So(err, ShouldNotBeNil)
 		})
@@ -474,7 +481,7 @@ func TestTimingWheel_deliver(t *testing.T) {
 		Convey("test timingwheel deliver failure with eventbus not found", func() {
 			mockBusWriter.EXPECT().Append(Any(), Any()).AnyTimes().Return([]string{""}, errors.ErrOffsetOnEnd)
 			err := tw.deliver(ctx, e)
-			So(err, ShouldBeNil)
+			So(err, ShouldNotBeNil)
 		})
 
 		Convey("test timingwheel deliver failure with append failed", func() {
@@ -486,7 +493,7 @@ func TestTimingWheel_deliver(t *testing.T) {
 		Convey("test timingwheel deliver success", func() {
 			mockBusWriter.EXPECT().Append(Any(), Any()).AnyTimes().Return([]string{""}, nil)
 			err := tw.deliver(ctx, e)
-			So(err, ShouldBeNil)
+			So(err, ShouldNotBeNil)
 		})
 	})
 }
@@ -591,7 +598,7 @@ func TestTimingWheelElement_pushBack(t *testing.T) {
 
 		Convey("push timing message failure causes start failed", func() {
 			tw.SetLeader(true)
-			mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(errors.New("test"))
+			mockSvc.EXPECT().CreateSystemEventbusIfNotExist(Any(), Any(), Any()).Times(1).Return(nil, errors.New("test"))
 			tm := newTimingMsg(ctx, event(1000))
 			twe := tw.twList.Back().Value.(*timingWheelElement)
 			result := twe.pushBack(ctx, tm)