1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 14:07:02 +09:00
any-sync/testutil/testnodeconf/testnodeconf.go
2023-05-23 14:47:24 +02:00

47 lines
1.1 KiB
Go

package testnodeconf
import (
"github.com/anyproto/any-sync/accountservice"
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/nodeconf"
"github.com/anyproto/any-sync/testutil/accounttest"
)
func GenNodeConfig(num int) (conf *Config) {
conf = &Config{}
if num <= 0 {
num = 1
}
for i := 0; i < num; i++ {
ac := &accounttest.AccountTestService{}
if err := ac.Init(nil); err != nil {
panic(err)
}
conf.nodes.Nodes = append(conf.nodes.Nodes, nodeconf.Node{
PeerId: ac.Account().PeerId,
Types: []nodeconf.NodeType{nodeconf.NodeTypeTree},
})
conf.configs = append(conf.configs, ac)
}
return conf
}
type Config struct {
nodes nodeconf.Configuration
configs []*accounttest.AccountTestService
}
func (c *Config) Init(a *app.App) (err error) { return }
func (c *Config) Name() string { return "config" }
func (c *Config) GetNodesConfId() string {
return "test"
}
func (c *Config) GetNodeConf() nodeconf.Configuration {
return c.nodes
}
func (c *Config) GetAccountService(idx int) accountservice.Service {
return c.configs[idx]
}