fix: Refuse to start if max_open_connections is below 5 (#2097)

* server refuses to start if max_open_connections is below 5

* suggested changes - Update internal/db/db.go

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
pull/2158/head
Gabriel Santos 4 years ago committed by GitHub
parent 0425384b49
commit 3521c21cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -95,6 +95,9 @@ func Open(dbType DbType, connectionUrl string, opt ...Option) (*DB, error) {
wrappedOpts = append(wrappedOpts, dbw.WithLogger(opts.withGormFormatter))
}
if opts.withMaxOpenConnections > 0 {
if opts.withMaxOpenConnections < 5 {
return nil, fmt.Errorf("max_open_connections cannot be below 5")
}
wrappedOpts = append(wrappedOpts, dbw.WithMaxOpenConnections(opts.withMaxOpenConnections))
}

@ -22,6 +22,7 @@ func TestOpen(t *testing.T) {
type args struct {
dbType DbType
connectionUrl string
opt []Option
}
tests := []struct {
name string
@ -44,6 +45,15 @@ func TestOpen(t *testing.T) {
},
wantErr: true,
},
{
name: "invalid - max_open_connections set to 3",
args: args{
dbType: Postgres,
connectionUrl: "",
opt: []Option{WithMaxOpenConnections(3)},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

Loading…
Cancel
Save