Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jul 15, 2024
1 parent 07b1402 commit 59681ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/csconfig/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (d *DatabaseCfg) ConnectionString() string {
} else {
connString = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=True", d.User, d.Password, d.Host, d.Port, d.DbName)
}

if d.Sslmode != "" {
connString = fmt.Sprintf("%s&tls=%s", connString, d.Sslmode)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/csconfig/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func TestLoadDBConfig(t *testing.T) {
},
},
expected: &DatabaseCfg{
Type: "sqlite",
DbPath: "./testdata/test.db",
MaxOpenConns: 10,
UseWal: ptr.Of(true),
Type: "sqlite",
DbPath: "./testdata/test.db",
MaxOpenConns: 10,
UseWal: ptr.Of(true),
DecisionBulkSize: defaultDecisionBulkSize,
},
},
Expand All @@ -49,6 +49,7 @@ func TestLoadDBConfig(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
err := tc.input.LoadDBConfig(false)
cstest.RequireErrorContains(t, err, tc.expectedErr)

if tc.expectedErr != "" {
return
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewClient(ctx context.Context, config *csconfig.DatabaseCfg) (*Client, erro

if config.Type == "sqlite" {
/*if it's the first startup, we want to touch and chmod file*/
if _, err := os.Stat(config.DbPath); os.IsNotExist(err) {
if _, err = os.Stat(config.DbPath); os.IsNotExist(err) {
f, err := os.OpenFile(config.DbPath, os.O_CREATE|os.O_RDWR, 0o600)
if err != nil {
return nil, fmt.Errorf("failed to create SQLite database file %q: %w", config.DbPath, err)
Expand All @@ -82,14 +82,14 @@ func NewClient(ctx context.Context, config *csconfig.DatabaseCfg) (*Client, erro
}
}
// Always try to set permissions to simplify a bit the code for windows (as the permissions set by OpenFile will be garbage)
if err := setFilePerm(config.DbPath, 0o640); err != nil {
return nil, fmt.Errorf("unable to set perms on %s: %v", config.DbPath, err)
if err = setFilePerm(config.DbPath, 0o640); err != nil {
return nil, fmt.Errorf("unable to set perms on %s: %w", config.DbPath, err)

Check warning on line 86 in pkg/database/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/database/database.go#L86

Added line #L86 was not covered by tests
}
}

drv, err := getEntDriver(typ, dia, config.ConnectionString(), config)
if err != nil {
return nil, fmt.Errorf("failed opening connection to %s: %v", config.Type, err)
return nil, fmt.Errorf("failed opening connection to %s: %w", config.Type, err)

Check warning on line 92 in pkg/database/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/database/database.go#L92

Added line #L92 was not covered by tests
}

client = ent.NewClient(ent.Driver(drv), entOpt)
Expand All @@ -101,7 +101,7 @@ func NewClient(ctx context.Context, config *csconfig.DatabaseCfg) (*Client, erro
}

if err = client.Schema.Create(ctx); err != nil {
return nil, fmt.Errorf("failed creating schema resources: %v", err)
return nil, fmt.Errorf("failed creating schema resources: %w", err)

Check warning on line 104 in pkg/database/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/database/database.go#L104

Added line #L104 was not covered by tests
}

return &Client{
Expand Down

0 comments on commit 59681ee

Please sign in to comment.