Skip to content

Commit

Permalink
Added pool size options for pg dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
memclutter committed Jan 6, 2022
1 parent 641ab80 commit 0ed993e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/corecli/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/urfave/cli/v2"
"io"
"reflect"
"strconv"
"strings"
)

Expand Down Expand Up @@ -73,6 +74,13 @@ func loadDependencyGoPgV10(v reflect.Value, options map[string]string, c *cli.Co
if err != nil {
return nil, fmt.Errorf("error parse data source name: %v", err)
}
if option, ok := options["poolSize"]; ok {
poolSize, err := strconv.Atoi(option)
if err != nil {
return nil, fmt.Errorf("invalid parse poolSize option: %v", err)
}
opt.PoolSize = poolSize
}
db := pg.Connect(opt)
if _, ok := options["ping"]; ok {
if err := db.Ping(c.Context); err != nil {
Expand Down
34 changes: 34 additions & 0 deletions pkg/corecli/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,40 @@ func Test_loadDependencyGoPgV10(t *testing.T) {
isNil: true,
err: fmt.Errorf(`error connect to database: dial tcp 127.0.0.1:2345: connect: connection refused`),
},
{
title: "Can load and set pool size go-pg v10 dependency correctly",
v: reflect.ValueOf(struct{}{}),
options: map[string]string{"dsn": "dsnDb", "poolSize": "2"},
app: &cli.App{
Name: "gocore",
Flags: []cli.Flag{
&cli.StringFlag{Name: "dsnDb"},
},
},
args: []string{
"gocore",
"--dsnDb", dsnDb,
},
isNil: false,
err: nil,
},
{
title: "Can't load and set pool size go-pg v10 dependency correctly",
v: reflect.ValueOf(struct{}{}),
options: map[string]string{"dsn": "dsnDb", "poolSize": "invalid"},
app: &cli.App{
Name: "gocore",
Flags: []cli.Flag{
&cli.StringFlag{Name: "dsnDb"},
},
},
args: []string{
"gocore",
"--dsnDb", dsnDb,
},
isNil: true,
err: fmt.Errorf(`invalid parse poolSize option: strconv.Atoi: parsing "invalid": invalid syntax`),
},
}

for _, table := range tables {
Expand Down

0 comments on commit 0ed993e

Please sign in to comment.