Update -normalise text, add config.DefaultOpts for clearer call sites (@kegsay review comments)

This commit is contained in:
Neil Alexander 2022-07-12 12:27:58 +01:00
parent 79e20b623a
commit b1ace48c72
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
22 changed files with 126 additions and 77 deletions

View file

@ -243,7 +243,10 @@ func (m *DendriteMonolith) Start() {
prefix := hex.EncodeToString(pk) prefix := hex.EncodeToString(pk)
cfg := &config.Dendrite{} cfg := &config.Dendrite{}
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk)) cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
cfg.Global.PrivateKey = sk cfg.Global.PrivateKey = sk
cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID) cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID)

View file

@ -82,7 +82,10 @@ func (m *DendriteMonolith) Start() {
m.YggdrasilNode = ygg m.YggdrasilNode = ygg
cfg := &config.Dendrite{} cfg := &config.Dendrite{}
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
cfg.Global.ServerName = gomatrixserverlib.ServerName(ygg.DerivedServerName()) cfg.Global.ServerName = gomatrixserverlib.ServerName(ygg.DerivedServerName())
cfg.Global.PrivateKey = ygg.PrivateKey() cfg.Global.PrivateKey = ygg.PrivateKey()
cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID) cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID)

View file

@ -181,7 +181,10 @@ func TestValidationOfApplicationServices(t *testing.T) {
// Set up a config // Set up a config
fakeConfig := &config.Dendrite{} fakeConfig := &config.Dendrite{}
fakeConfig.Defaults(true, true) fakeConfig.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
fakeConfig.Global.ServerName = "localhost" fakeConfig.Global.ServerName = "localhost"
fakeConfig.ClientAPI.Derived.ApplicationServices = []config.ApplicationService{fakeApplicationService} fakeConfig.ClientAPI.Derived.ApplicationServices = []config.ApplicationService{fakeApplicationService}

View file

@ -127,7 +127,10 @@ func main() {
}() }()
cfg := &config.Dendrite{} cfg := &config.Dendrite{}
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk)) cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
cfg.Global.PrivateKey = sk cfg.Global.PrivateKey = sk
cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID) cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID)

View file

@ -78,7 +78,10 @@ func main() {
if configFlagSet { if configFlagSet {
cfg = setup.ParseFlags(true) cfg = setup.ParseFlags(true)
} else { } else {
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
cfg.Global.JetStream.StoragePath = config.Path(fmt.Sprintf("%s/", *instanceName)) cfg.Global.JetStream.StoragePath = config.Path(fmt.Sprintf("%s/", *instanceName))
cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-account.db", *instanceName)) cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-account.db", *instanceName))
cfg.MediaAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-mediaapi.db", *instanceName)) cfg.MediaAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-mediaapi.db", *instanceName))

View file

@ -14,7 +14,7 @@ func main() {
defaultsForCI := flag.Bool("ci", false, "Populate the configuration with sane defaults for use in CI") defaultsForCI := flag.Bool("ci", false, "Populate the configuration with sane defaults for use in CI")
serverName := flag.String("server", "", "The domain name of the server if not 'localhost'") serverName := flag.String("server", "", "The domain name of the server if not 'localhost'")
dbURI := flag.String("db", "", "The DB URI to use for all components if not SQLite files") dbURI := flag.String("db", "", "The DB URI to use for all components if not SQLite files")
normalise := flag.String("normalise", "", "Normalise a given configuration file") normalise := flag.String("normalise", "", "Normalise an existing configuration file by adding new/missing options and defaults")
polylith := flag.Bool("polylith", false, "Generate a config that makes sense for polylith deployments") polylith := flag.Bool("polylith", false, "Generate a config that makes sense for polylith deployments")
flag.Parse() flag.Parse()
@ -23,7 +23,10 @@ func main() {
cfg = &config.Dendrite{ cfg = &config.Dendrite{
Version: config.Version, Version: config.Version,
} }
cfg.Defaults(true, !*polylith) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: !*polylith,
})
} else { } else {
var err error var err error
if cfg, err = config.Load(*normalise, !*polylith); err != nil { if cfg, err = config.Load(*normalise, !*polylith); err != nil {

View file

@ -75,7 +75,10 @@ func TestMain(m *testing.M) {
// Draw up just enough Dendrite config for the server key // Draw up just enough Dendrite config for the server key
// API to work. // API to work.
cfg := &config.Dendrite{} cfg := &config.Dendrite{}
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name) cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
cfg.Global.PrivateKey = testPriv cfg.Global.PrivateKey = testPriv
cfg.Global.JetStream.InMemory = true cfg.Global.JetStream.InMemory = true

View file

@ -252,7 +252,10 @@ func testFederationAPIJoinThenKeyUpdate(t *testing.T, dbType test.DBType) {
func TestRoomsV3URLEscapeDoNot404(t *testing.T) { func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
_, privKey, _ := ed25519.GenerateKey(nil) _, privKey, _ := ed25519.GenerateKey(nil)
cfg := &config.Dendrite{} cfg := &config.Dendrite{}
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
cfg.Global.KeyID = gomatrixserverlib.KeyID("ed25519:auto") cfg.Global.KeyID = gomatrixserverlib.KeyID("ed25519:auto")
cfg.Global.ServerName = gomatrixserverlib.ServerName("localhost") cfg.Global.ServerName = gomatrixserverlib.ServerName("localhost")
cfg.Global.PrivateKey = privKey cfg.Global.PrivateKey = privKey

View file

@ -211,7 +211,10 @@ func loadConfig(
monolithic bool, monolithic bool,
) (*Dendrite, error) { ) (*Dendrite, error) {
var c Dendrite var c Dendrite
c.Defaults(false, monolithic) c.Defaults(DefaultOpts{
Generate: false,
Monolithic: monolithic,
})
c.IsMonolith = monolithic c.IsMonolith = monolithic
var err error var err error
@ -292,11 +295,16 @@ func (config *Dendrite) Derive() error {
return nil return nil
} }
type DefaultOpts struct {
Generate bool
Monolithic bool
}
// SetDefaults sets default config values if they are not explicitly set. // SetDefaults sets default config values if they are not explicitly set.
func (c *Dendrite) Defaults(generate bool, isMonolith bool) { func (c *Dendrite) Defaults(opts DefaultOpts) {
c.Version = Version c.Version = Version
if generate { if opts.Generate {
c.Logging = []LogrusHook{ c.Logging = []LogrusHook{
{ {
Type: "file", Type: "file",
@ -308,17 +316,16 @@ func (c *Dendrite) Defaults(generate bool, isMonolith bool) {
} }
} }
c.Global.Defaults(generate, isMonolith) c.Global.Defaults(opts)
c.ClientAPI.Defaults(generate, isMonolith) c.ClientAPI.Defaults(opts)
c.FederationAPI.Defaults(generate, isMonolith) c.FederationAPI.Defaults(opts)
c.KeyServer.Defaults(generate, isMonolith) c.KeyServer.Defaults(opts)
c.MediaAPI.Defaults(generate, isMonolith) c.MediaAPI.Defaults(opts)
c.RoomServer.Defaults(generate, isMonolith) c.RoomServer.Defaults(opts)
c.SyncAPI.Defaults(generate, isMonolith) c.SyncAPI.Defaults(opts)
c.UserAPI.Defaults(generate, isMonolith) c.UserAPI.Defaults(opts)
c.AppServiceAPI.Defaults(generate, isMonolith) c.AppServiceAPI.Defaults(opts)
c.MSCs.Defaults(generate, isMonolith) c.MSCs.Defaults(opts)
c.Wiring() c.Wiring()
} }

View file

@ -40,14 +40,14 @@ type AppServiceAPI struct {
ConfigFiles []string `yaml:"config_files"` ConfigFiles []string `yaml:"config_files"`
} }
func (c *AppServiceAPI) Defaults(generate bool, isMonolith bool) { func (c *AppServiceAPI) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7777" c.InternalAPI.Listen = "http://localhost:7777"
c.InternalAPI.Connect = "http://localhost:7777" c.InternalAPI.Connect = "http://localhost:7777"
c.Database.Defaults(5) c.Database.Defaults(5)
} }
if generate { if opts.Generate {
if !isMonolith { if !opts.Monolithic {
c.Database.ConnectionString = "file:appservice.db" c.Database.ConnectionString = "file:appservice.db"
} }
} }

View file

@ -51,8 +51,8 @@ type ClientAPI struct {
MSCs *MSCs `yaml:"-"` MSCs *MSCs `yaml:"-"`
} }
func (c *ClientAPI) Defaults(generate bool, isMonolith bool) { func (c *ClientAPI) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7771" c.InternalAPI.Listen = "http://localhost:7771"
c.InternalAPI.Connect = "http://localhost:7771" c.InternalAPI.Connect = "http://localhost:7771"
c.ExternalAPI.Listen = "http://[::]:8071" c.ExternalAPI.Listen = "http://[::]:8071"

View file

@ -30,8 +30,8 @@ type FederationAPI struct {
PreferDirectFetch bool `yaml:"prefer_direct_fetch"` PreferDirectFetch bool `yaml:"prefer_direct_fetch"`
} }
func (c *FederationAPI) Defaults(generate bool, isMonolith bool) { func (c *FederationAPI) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7772" c.InternalAPI.Listen = "http://localhost:7772"
c.InternalAPI.Connect = "http://localhost:7772" c.InternalAPI.Connect = "http://localhost:7772"
c.ExternalAPI.Listen = "http://[::]:8072" c.ExternalAPI.Listen = "http://[::]:8072"
@ -39,7 +39,7 @@ func (c *FederationAPI) Defaults(generate bool, isMonolith bool) {
} }
c.FederationMaxRetries = 16 c.FederationMaxRetries = 16
c.DisableTLSValidation = false c.DisableTLSValidation = false
if generate { if opts.Generate {
c.KeyPerspectives = KeyPerspectives{ c.KeyPerspectives = KeyPerspectives{
{ {
ServerName: "matrix.org", ServerName: "matrix.org",
@ -55,7 +55,7 @@ func (c *FederationAPI) Defaults(generate bool, isMonolith bool) {
}, },
}, },
} }
if !isMonolith { if !opts.Monolithic {
c.Database.ConnectionString = "file:federationapi.db" c.Database.ConnectionString = "file:federationapi.db"
} }
} }

View file

@ -80,8 +80,8 @@ type Global struct {
Cache Cache `yaml:"cache"` Cache Cache `yaml:"cache"`
} }
func (c *Global) Defaults(generate bool, isMonolith bool) { func (c *Global) Defaults(opts DefaultOpts) {
if generate { if opts.Generate {
c.ServerName = "localhost" c.ServerName = "localhost"
c.PrivateKeyPath = "matrix_key.pem" c.PrivateKeyPath = "matrix_key.pem"
_, c.PrivateKey, _ = ed25519.GenerateKey(rand.New(rand.NewSource(0))) _, c.PrivateKey, _ = ed25519.GenerateKey(rand.New(rand.NewSource(0)))
@ -92,16 +92,16 @@ func (c *Global) Defaults(generate bool, isMonolith bool) {
} }
} }
c.KeyValidityPeriod = time.Hour * 24 * 7 c.KeyValidityPeriod = time.Hour * 24 * 7
if isMonolith { if opts.Monolithic {
c.DatabaseOptions.Defaults(90) c.DatabaseOptions.Defaults(90)
} }
c.JetStream.Defaults(generate) c.JetStream.Defaults(opts)
c.Metrics.Defaults(generate) c.Metrics.Defaults(opts)
c.DNSCache.Defaults() c.DNSCache.Defaults()
c.Sentry.Defaults() c.Sentry.Defaults()
c.ServerNotices.Defaults(generate) c.ServerNotices.Defaults(opts)
c.ReportStats.Defaults() c.ReportStats.Defaults()
c.Cache.Defaults(generate) c.Cache.Defaults()
} }
func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) { func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) {
@ -145,9 +145,9 @@ type Metrics struct {
} `yaml:"basic_auth"` } `yaml:"basic_auth"`
} }
func (c *Metrics) Defaults(generate bool) { func (c *Metrics) Defaults(opts DefaultOpts) {
c.Enabled = false c.Enabled = false
if generate { if opts.Generate {
c.BasicAuth.Username = "metrics" c.BasicAuth.Username = "metrics"
c.BasicAuth.Password = "metrics" c.BasicAuth.Password = "metrics"
} }
@ -169,8 +169,8 @@ type ServerNotices struct {
RoomName string `yaml:"room_name"` RoomName string `yaml:"room_name"`
} }
func (c *ServerNotices) Defaults(generate bool) { func (c *ServerNotices) Defaults(opts DefaultOpts) {
if generate { if opts.Generate {
c.Enabled = true c.Enabled = true
c.LocalPart = "_server" c.LocalPart = "_server"
c.DisplayName = "Server Alert" c.DisplayName = "Server Alert"
@ -186,7 +186,7 @@ type Cache struct {
MaxAge time.Duration `yaml:"max_age"` MaxAge time.Duration `yaml:"max_age"`
} }
func (c *Cache) Defaults(generate bool) { func (c *Cache) Defaults() {
c.EstimatedMaxSize = 1024 * 1024 * 1024 // 1GB c.EstimatedMaxSize = 1024 * 1024 * 1024 // 1GB
c.MaxAge = time.Hour c.MaxAge = time.Hour
} }

View file

@ -27,10 +27,10 @@ func (c *JetStream) Durable(name string) string {
return c.Prefixed(name) return c.Prefixed(name)
} }
func (c *JetStream) Defaults(generate bool) { func (c *JetStream) Defaults(opts DefaultOpts) {
c.Addresses = []string{} c.Addresses = []string{}
c.TopicPrefix = "Dendrite" c.TopicPrefix = "Dendrite"
if generate { if opts.Generate {
c.StoragePath = Path("./") c.StoragePath = Path("./")
} }
} }

View file

@ -8,14 +8,14 @@ type KeyServer struct {
Database DatabaseOptions `yaml:"database,omitempty"` Database DatabaseOptions `yaml:"database,omitempty"`
} }
func (c *KeyServer) Defaults(generate bool, isMonolith bool) { func (c *KeyServer) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7779" c.InternalAPI.Listen = "http://localhost:7779"
c.InternalAPI.Connect = "http://localhost:7779" c.InternalAPI.Connect = "http://localhost:7779"
c.Database.Defaults(10) c.Database.Defaults(10)
} }
if generate { if opts.Generate {
if !isMonolith { if !opts.Monolithic {
c.Database.ConnectionString = "file:keyserver.db" c.Database.ConnectionString = "file:keyserver.db"
} }
} }

View file

@ -38,8 +38,8 @@ type MediaAPI struct {
// DefaultMaxFileSizeBytes defines the default file size allowed in transfers // DefaultMaxFileSizeBytes defines the default file size allowed in transfers
var DefaultMaxFileSizeBytes = FileSizeBytes(10485760) var DefaultMaxFileSizeBytes = FileSizeBytes(10485760)
func (c *MediaAPI) Defaults(generate bool, isMonolith bool) { func (c *MediaAPI) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7774" c.InternalAPI.Listen = "http://localhost:7774"
c.InternalAPI.Connect = "http://localhost:7774" c.InternalAPI.Connect = "http://localhost:7774"
c.ExternalAPI.Listen = "http://[::]:8074" c.ExternalAPI.Listen = "http://[::]:8074"
@ -47,7 +47,7 @@ func (c *MediaAPI) Defaults(generate bool, isMonolith bool) {
} }
c.MaxFileSizeBytes = DefaultMaxFileSizeBytes c.MaxFileSizeBytes = DefaultMaxFileSizeBytes
c.MaxThumbnailGenerators = 10 c.MaxThumbnailGenerators = 10
if generate { if opts.Generate {
c.ThumbnailSizes = []ThumbnailSize{ c.ThumbnailSizes = []ThumbnailSize{
{ {
Width: 32, Width: 32,
@ -65,7 +65,7 @@ func (c *MediaAPI) Defaults(generate bool, isMonolith bool) {
ResizeMethod: "scale", ResizeMethod: "scale",
}, },
} }
if !isMonolith { if !opts.Monolithic {
c.Database.ConnectionString = "file:mediaapi.db" c.Database.ConnectionString = "file:mediaapi.db"
} }
c.BasePath = "./media_store" c.BasePath = "./media_store"

View file

@ -13,12 +13,12 @@ type MSCs struct {
Database DatabaseOptions `yaml:"database,omitempty"` Database DatabaseOptions `yaml:"database,omitempty"`
} }
func (c *MSCs) Defaults(generate bool, isMonolith bool) { func (c *MSCs) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.Database.Defaults(5) c.Database.Defaults(5)
} }
if generate { if opts.Generate {
if !isMonolith { if !opts.Monolithic {
c.Database.ConnectionString = "file:mscs.db" c.Database.ConnectionString = "file:mscs.db"
} }
} }

View file

@ -8,14 +8,14 @@ type RoomServer struct {
Database DatabaseOptions `yaml:"database,omitempty"` Database DatabaseOptions `yaml:"database,omitempty"`
} }
func (c *RoomServer) Defaults(generate bool, isMonolith bool) { func (c *RoomServer) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7770" c.InternalAPI.Listen = "http://localhost:7770"
c.InternalAPI.Connect = "http://localhost:7770" c.InternalAPI.Connect = "http://localhost:7770"
c.Database.Defaults(10) c.Database.Defaults(10)
} }
if generate { if opts.Generate {
if !isMonolith { if !opts.Monolithic {
c.Database.ConnectionString = "file:roomserver.db" c.Database.ConnectionString = "file:roomserver.db"
} }
} }

View file

@ -11,15 +11,15 @@ type SyncAPI struct {
RealIPHeader string `yaml:"real_ip_header"` RealIPHeader string `yaml:"real_ip_header"`
} }
func (c *SyncAPI) Defaults(generate bool, isMonolith bool) { func (c *SyncAPI) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7773" c.InternalAPI.Listen = "http://localhost:7773"
c.InternalAPI.Connect = "http://localhost:7773" c.InternalAPI.Connect = "http://localhost:7773"
c.ExternalAPI.Listen = "http://localhost:8073" c.ExternalAPI.Listen = "http://localhost:8073"
c.Database.Defaults(10) c.Database.Defaults(10)
} }
if generate { if opts.Generate {
if !isMonolith { if !opts.Monolithic {
c.Database.ConnectionString = "file:syncapi.db" c.Database.ConnectionString = "file:syncapi.db"
} }
} }

View file

@ -23,16 +23,16 @@ type UserAPI struct {
const DefaultOpenIDTokenLifetimeMS = 3600000 // 60 minutes const DefaultOpenIDTokenLifetimeMS = 3600000 // 60 minutes
func (c *UserAPI) Defaults(generate bool, isMonolith bool) { func (c *UserAPI) Defaults(opts DefaultOpts) {
if !isMonolith { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7781" c.InternalAPI.Listen = "http://localhost:7781"
c.InternalAPI.Connect = "http://localhost:7781" c.InternalAPI.Connect = "http://localhost:7781"
c.AccountDatabase.Defaults(10) c.AccountDatabase.Defaults(10)
} }
c.BCryptCost = bcrypt.DefaultCost c.BCryptCost = bcrypt.DefaultCost
c.OpenIDTokenLifetimeMS = DefaultOpenIDTokenLifetimeMS c.OpenIDTokenLifetimeMS = DefaultOpenIDTokenLifetimeMS
if generate { if opts.Generate {
if !isMonolith { if !opts.Monolithic {
c.AccountDatabase.ConnectionString = "file:userapi_accounts.db" c.AccountDatabase.ConnectionString = "file:userapi_accounts.db"
} }
} }

View file

@ -544,7 +544,10 @@ func (r *testRoomserverAPI) QueryMembershipForUser(ctx context.Context, req *roo
func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserver.RoomserverInternalAPI, events []*gomatrixserverlib.HeaderedEvent) *mux.Router { func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserver.RoomserverInternalAPI, events []*gomatrixserverlib.HeaderedEvent) *mux.Router {
t.Helper() t.Helper()
cfg := &config.Dendrite{} cfg := &config.Dendrite{}
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
cfg.Global.ServerName = "localhost" cfg.Global.ServerName = "localhost"
cfg.MSCs.Database.ConnectionString = "file:msc2836_test.db" cfg.MSCs.Database.ConnectionString = "file:msc2836_test.db"
cfg.MSCs.MSCs = []string{"msc2836"} cfg.MSCs.MSCs = []string{"msc2836"}

View file

@ -30,13 +30,22 @@ import (
func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, func()) { func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, func()) {
var cfg config.Dendrite var cfg config.Dendrite
cfg.Defaults(false, true) cfg.Defaults(config.DefaultOpts{
Generate: false,
Monolithic: true,
})
cfg.Global.JetStream.InMemory = true cfg.Global.JetStream.InMemory = true
switch dbType { switch dbType {
case test.DBTypePostgres: case test.DBTypePostgres:
cfg.Global.Defaults(true, true) // autogen a signing key cfg.Global.Defaults(config.DefaultOpts{ // autogen a signing key
cfg.MediaAPI.Defaults(true, true) // autogen a media path Generate: true,
Monolithic: true,
})
cfg.MediaAPI.Defaults(config.DefaultOpts{ // autogen a media path
Generate: true,
Monolithic: true,
})
// use a distinct prefix else concurrent postgres/sqlite runs will clash since NATS will use // use a distinct prefix else concurrent postgres/sqlite runs will clash since NATS will use
// the file system event with InMemory=true :( // the file system event with InMemory=true :(
cfg.Global.JetStream.TopicPrefix = fmt.Sprintf("Test_%d_", dbType) cfg.Global.JetStream.TopicPrefix = fmt.Sprintf("Test_%d_", dbType)
@ -49,7 +58,10 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f
} }
return base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics), close return base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics), close
case test.DBTypeSQLite: case test.DBTypeSQLite:
cfg.Defaults(true, true) // sets a sqlite db per component cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
}) // sets a sqlite db per component
// use a distinct prefix else concurrent postgres/sqlite runs will clash since NATS will use // use a distinct prefix else concurrent postgres/sqlite runs will clash since NATS will use
// the file system event with InMemory=true :( // the file system event with InMemory=true :(
cfg.Global.JetStream.TopicPrefix = fmt.Sprintf("Test_%d_", dbType) cfg.Global.JetStream.TopicPrefix = fmt.Sprintf("Test_%d_", dbType)
@ -82,7 +94,10 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f
func Base(cfg *config.Dendrite) (*base.BaseDendrite, nats.JetStreamContext, *nats.Conn) { func Base(cfg *config.Dendrite) (*base.BaseDendrite, nats.JetStreamContext, *nats.Conn) {
if cfg == nil { if cfg == nil {
cfg = &config.Dendrite{} cfg = &config.Dendrite{}
cfg.Defaults(true, true) cfg.Defaults(config.DefaultOpts{
Generate: true,
Monolithic: true,
})
} }
cfg.Global.JetStream.InMemory = true cfg.Global.JetStream.InMemory = true
base := base.NewBaseDendrite(cfg, "Tests") base := base.NewBaseDendrite(cfg, "Tests")