mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 18:20:33 +09:00
[feat-kanban-subscr-GO-90] fix tests
This commit is contained in:
parent
e7b1cf5441
commit
34c46f4c36
13 changed files with 151 additions and 9 deletions
|
@ -38,7 +38,7 @@ type ComponentRunnable interface {
|
|||
// Non-nil error also will be aborted app start
|
||||
Run(ctx context.Context) (err error)
|
||||
// Close will be called when app shutting down
|
||||
// Also will be called when service return error on Init or Run stage
|
||||
// Also will be called when service return error on InitGroups or Run stage
|
||||
// Non-nil error will be printed to log
|
||||
Close() (err error)
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ func (v *bundledRelation) ReadMeta(ctx context.Context, _ ChangeReceiver) (doc s
|
|||
|
||||
func (v *bundledRelation) PushChange(params PushChangeParams) (id string, err error) {
|
||||
if params.State.ChangeId() == "" {
|
||||
// allow the first changes created by Init
|
||||
// allow the first changes created by InitGroups
|
||||
return "virtual", nil
|
||||
}
|
||||
return "", ErrReadOnly
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
type GroupCheckBox struct {
|
||||
}
|
||||
|
||||
func (gCh *GroupCheckBox) Init(reqFilters []*model.BlockContentDataviewFilter) error {
|
||||
func (gCh *GroupCheckBox) InitGroups(reqFilters []*model.BlockContentDataviewFilter) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ type GroupStatus struct {
|
|||
Options []*model.RelationOption
|
||||
}
|
||||
|
||||
func (gs *GroupStatus) Init(reqFilters []*model.BlockContentDataviewFilter) error {
|
||||
func (gs *GroupStatus) InitGroups(reqFilters []*model.BlockContentDataviewFilter) error {
|
||||
options, err := gs.store.GetAggregatedOptions(bundle.RelationKeyStatus.String())
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -17,7 +17,7 @@ type GroupTag struct {
|
|||
Records []database.Record
|
||||
}
|
||||
|
||||
func (t *GroupTag) Init(reqFilters []*model.BlockContentDataviewFilter) error {
|
||||
func (t *GroupTag) InitGroups(reqFilters []*model.BlockContentDataviewFilter) error {
|
||||
filters := []*model.BlockContentDataviewFilter{
|
||||
{RelationKey: string(bundle.RelationKeyIsDeleted), Condition: model.BlockContentDataviewFilter_Equal},
|
||||
{RelationKey: string(bundle.RelationKeyIsArchived), Condition: model.BlockContentDataviewFilter_Equal},
|
||||
|
|
|
@ -16,11 +16,16 @@ func New() *Service{
|
|||
}
|
||||
|
||||
type Grouper interface {
|
||||
Init(reqFilters []*model.BlockContentDataviewFilter) error
|
||||
InitGroups(reqFilters []*model.BlockContentDataviewFilter) error
|
||||
MakeGroups() ([]Group, error)
|
||||
MakeDataViewGroups() ([]*model.BlockContentDataviewGroup, error)
|
||||
}
|
||||
|
||||
|
||||
type KanbanService interface {
|
||||
app.ComponentRunnable
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
objectStore objectstore.ObjectStore
|
||||
groupColumns map[model.RelationFormat]Grouper
|
||||
|
|
|
@ -306,7 +306,7 @@ func (mw *Middleware) ObjectRelationSearchDistinct(_ context.Context, req *pb.Rp
|
|||
return errResponse(err)
|
||||
}
|
||||
|
||||
if err := grouper.Init(req.Filters); err != nil {
|
||||
if err := grouper.InitGroups(req.Filters); err != nil {
|
||||
return errResponse(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ func (s *service) SubscribeGroups(req pb.RpcObjectGroupsSubscribeRequest) (*pb.R
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if err := grouper.Init(req.Filters); err != nil {
|
||||
if err := grouper.InitGroups(req.Filters); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package subscription
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-middleware/util/testMock/mockKanban"
|
||||
"testing"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/app/testapp"
|
||||
|
@ -316,6 +317,7 @@ func newFixture(t *testing.T) *fixture {
|
|||
}}
|
||||
a.Register(fx.Service)
|
||||
a.Register(fx.sender)
|
||||
a.Register(fx.kanban)
|
||||
fx.store.EXPECT().SubscribeForAll(gomock.Any())
|
||||
require.NoError(t, a.Start(context.Background()))
|
||||
return fx
|
||||
|
@ -327,5 +329,6 @@ type fixture struct {
|
|||
ctrl *gomock.Controller
|
||||
store *testMock.MockObjectStore
|
||||
sender *testapp.EventSender
|
||||
kanban *mockKanban.MockKanbanService
|
||||
events []*pb.Event
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ func GatewayAddr() string {
|
|||
func (g *gateway) Init(a *app.App) (err error) {
|
||||
g.Node = a.MustComponent(core.CName).(core.Service)
|
||||
g.addr = GatewayAddr()
|
||||
log.Debugf("gateway.Init: %s", g.addr)
|
||||
log.Debugf("gateway.InitGroups: %s", g.addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
2
util/testMock/mockKanban/kanban.go
Normal file
2
util/testMock/mockKanban/kanban.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
//go:generate mockgen -package mockKanban -destination kanban_mock.go github.com/anytypeio/go-anytype-middleware/core/kanban KanbanService
|
||||
package mockKanban
|
66
util/testMock/mockStatus/gomock_reflect_2441392563/prog.go
Normal file
66
util/testMock/mockStatus/gomock_reflect_2441392563/prog.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/mock/mockgen/model"
|
||||
|
||||
pkg_ "github.com/anytypeio/go-anytype-middleware/core/status"
|
||||
)
|
||||
|
||||
var output = flag.String("output", "", "The output file name, or empty to use stdout.")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
its := []struct{
|
||||
sym string
|
||||
typ reflect.Type
|
||||
}{
|
||||
|
||||
{ "Service", reflect.TypeOf((*pkg_.Service)(nil)).Elem()},
|
||||
|
||||
}
|
||||
pkg := &model.Package{
|
||||
// NOTE: This behaves contrary to documented behaviour if the
|
||||
// package name is not the final component of the import path.
|
||||
// The reflect package doesn't expose the package name, though.
|
||||
Name: path.Base("github.com/anytypeio/go-anytype-middleware/core/status"),
|
||||
}
|
||||
|
||||
for _, it := range its {
|
||||
intf, err := model.InterfaceFromInterfaceType(it.typ)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
intf.Name = it.sym
|
||||
pkg.Interfaces = append(pkg.Interfaces, intf)
|
||||
}
|
||||
|
||||
outfile := os.Stdout
|
||||
if len(*output) != 0 {
|
||||
var err error
|
||||
outfile, err = os.Create(*output)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
|
||||
}
|
||||
defer func() {
|
||||
if err := outfile.Close(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
66
util/testMock/mockStatus/gomock_reflect_4193689862/prog.go
Normal file
66
util/testMock/mockStatus/gomock_reflect_4193689862/prog.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/mock/mockgen/model"
|
||||
|
||||
pkg_ "github.com/anytypeio/go-anytype-middleware/core/status"
|
||||
)
|
||||
|
||||
var output = flag.String("output", "", "The output file name, or empty to use stdout.")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
its := []struct{
|
||||
sym string
|
||||
typ reflect.Type
|
||||
}{
|
||||
|
||||
{ "Service", reflect.TypeOf((*pkg_.Service)(nil)).Elem()},
|
||||
|
||||
}
|
||||
pkg := &model.Package{
|
||||
// NOTE: This behaves contrary to documented behaviour if the
|
||||
// package name is not the final component of the import path.
|
||||
// The reflect package doesn't expose the package name, though.
|
||||
Name: path.Base("github.com/anytypeio/go-anytype-middleware/core/status"),
|
||||
}
|
||||
|
||||
for _, it := range its {
|
||||
intf, err := model.InterfaceFromInterfaceType(it.typ)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
intf.Name = it.sym
|
||||
pkg.Interfaces = append(pkg.Interfaces, intf)
|
||||
}
|
||||
|
||||
outfile := os.Stdout
|
||||
if len(*output) != 0 {
|
||||
var err error
|
||||
outfile, err = os.Create(*output)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
|
||||
}
|
||||
defer func() {
|
||||
if err := outfile.Close(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue