starsz commented on a change in pull request #1318:
URL: https://github.com/apache/apisix-dashboard/pull/1318#discussion_r559278931



##########
File path: api/internal/core/store/store_mock.go
##########
@@ -18,48 +18,184 @@ package store
 
 import (
        "context"
+       "encoding/json"
+       "fmt"
+       "sort"
 
+       "github.com/apisix/manager-api/internal/core/entity"
+       "github.com/shiningrush/droplet/data"
        "github.com/stretchr/testify/mock"
 )
 
-type MockInterface struct {
-       mock.Mock
+type Mock struct {
+       MockInterface
+       storage   map[string]interface{}
+       validator Validator
+       keyFunc   func(obj interface{}) string
 }
 
-func (m *MockInterface) Get(key string) (interface{}, error) {
-       ret := m.Mock.Called(key)
-       return ret.Get(0), ret.Error(1)
+func NewMock(keyFunc func(obj interface{}) string, validator Validator) *Mock {
+       m := &Mock{
+               storage:   make(map[string]interface{}),
+               validator: validator,
+               keyFunc:   keyFunc,
+       }
+
+       m.onCreate()
+       m.onGet()
+       m.onUpdate()
+       m.onList()
+       m.onBatchDelete()
+       return m
+}
+
+func (m *Mock) create(ctx context.Context, obj interface{}) (interface{}, 
error) {
+       if setter, ok := obj.(entity.BaseInfoSetter); ok {
+               info := setter.GetBaseInfo()
+               info.Creating()
+       }
+
+       if m.validator != nil {
+               if err := m.validator.Validate(obj); err != nil {
+                       return nil, err
+               }
+       }
+
+       key := m.keyFunc(obj)
+       if key == "" {
+               return nil, fmt.Errorf("key is required")

Review comment:
       Updated.

##########
File path: api/internal/core/store/store_mock.go
##########
@@ -18,48 +18,184 @@ package store
 
 import (
        "context"
+       "encoding/json"
+       "fmt"
+       "sort"
 
+       "github.com/apisix/manager-api/internal/core/entity"
+       "github.com/shiningrush/droplet/data"
        "github.com/stretchr/testify/mock"
 )
 
-type MockInterface struct {
-       mock.Mock
+type Mock struct {
+       MockInterface

Review comment:
       Updated




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to