Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code committed Nov 20, 2024
1 parent 61e8d6f commit e3eda83
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ linters-settings:
- name: add-constant
disabled: true
- name: cognitive-complexity
disabled: false
exclude:
- "**_test.go"
disabled: true
- name: function-length
disabled: true
- name: var-naming
Expand All @@ -97,5 +95,3 @@ linters-settings:
- "fmt.Println"
- name: import-shadowing
disabled: true
- name: cognitive-complexity
disabled: true
2 changes: 1 addition & 1 deletion db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Config struct {
func NewDefConfig() Config {
return Config{
Driver: SqliteDriver,
Source: os.ExpandEnv("$HOME/.coastdao/coastdao.db"),
Source: os.ExpandEnv("$HOME/.my/my.db"),
ConnMaxIdleTime: time.Hour,
ConnMaxLifeTime: time.Hour,
MaxIdleConn: 10,
Expand Down
20 changes: 10 additions & 10 deletions db/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type ConfigTestSuite struct {

func (suite *ConfigTestSuite) TestNewDefConfig() {
config := db.NewDefConfig()
config.Source = "root:root@tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local"
config.Source = "root:root@tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local"
suite.Equal(`driver: sqlite
source: '****:****@tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local'
source: '****:****@tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local'
conn_max_idle_time: 1h0m0s
conn_max_life_time: 1h0m0s
max_idle_conn: 10
Expand Down Expand Up @@ -47,23 +47,23 @@ func TestSourceDesensitization(t *testing.T) {
}{
{
name: "test1",
source: "coastdao.db",
want: "coastdao.db",
source: "my.db",
want: "my.db",
},
{
name: "test2",
source: "root:root@tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local",
want: "****:****@tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local",
source: "root:root@tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local",
want: "****:****@tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local",
},
{
name: "test3",
source: "root@tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local",
want: "*:*@tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local",
source: "root@tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local",
want: "*:*@tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local",
},
{
name: "test4",
source: "tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local",
want: "tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local",
source: "tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local",
want: "tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local",
},
}
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions db/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestMysql_CheckSource(t *testing.T) {
}{
{
name: "test1",
source: "root:root@tcp(127.0.0.1:3306)/coastdao?charset=utf8mb4&parseTime=True&loc=Local",
source: "root:root@tcp(127.0.0.1:3306)/my?charset=utf8mb4&parseTime=True&loc=Local",
wantErr: assert.NoError,
},
{
Expand All @@ -25,7 +25,7 @@ func TestMysql_CheckSource(t *testing.T) {
},
{
name: "test3",
source: "coastdao",
source: "my",
wantErr: assert.Error,
},
}
Expand Down
22 changes: 11 additions & 11 deletions db/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSqlite_CheckSource(t *testing.T) {
}{
{
name: "test1",
source: "coastdao.db",
source: "my.db",
wantErr: assert.NoError,
},
{
Expand All @@ -30,12 +30,12 @@ func TestSqlite_CheckSource(t *testing.T) {
},
{
name: "test3",
source: "coastdao",
source: "my",
wantErr: assert.Error,
},
{
name: "test4",
source: "file:coastdao.db?mode=memory",
source: "file:my.db?mode=memory",
wantErr: assert.NoError,
},
}
Expand All @@ -57,25 +57,25 @@ func (suite *SqliteTestSuite) SetupTest() {
}

func (suite *SqliteTestSuite) TestOpen() {
suite.NotNil(suite.driver.Open("coastdao.db"))
suite.NotNil(suite.driver.Open("my.db"))
}

func (suite *SqliteTestSuite) TestOpen2() {
source := "${HOME}/.coastdao-keeper/coastdao-keeper.db"
source := "${HOME}/.my/my.db"
suite.T().Log(os.ExpandEnv(source))
suite.NotNil(suite.driver.Open(os.ExpandEnv(source)))
}

func (suite *SqliteTestSuite) TestGetDatabaseName() {
source := "coastdao.db"
suite.Equal("coastdao", suite.driver.GetDatabaseName(source))
source := "my.db"
suite.Equal("my", suite.driver.GetDatabaseName(source))

source = suite.T().TempDir() + "/coastdao.db"
suite.Equal("coastdao", suite.driver.GetDatabaseName(source))
source = suite.T().TempDir() + "/my.db"
suite.Equal("my", suite.driver.GetDatabaseName(source))
}

func (suite *SqliteTestSuite) TestCreateDB() {
source := suite.T().TempDir() + "/coastdao.db"
source := suite.T().TempDir() + "/my.db"
suite.Require().NoError(suite.driver.CreateDB(log.NewNopLogger(), db.Config{Source: source}))
defer func() {
suite.Require().NoError(suite.driver.DropDB(log.NewNopLogger(), db.Config{Source: source}))
Expand All @@ -84,7 +84,7 @@ func (suite *SqliteTestSuite) TestCreateDB() {
suite.Require().NoError(err)
suite.Require().NotNil(stat)
suite.True(stat.IsDir())
suite.Equal("coastdao.db", stat.Name())
suite.Equal("my.db", stat.Name())
}

func TestSqliteTestSuite(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions pprof/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func (s *Server) Start(ctx context.Context, group *errgroup.Group) error {
}

s.logger.Info("starting pprof server", "addr", fmt.Sprintf("http://%s", s.pprof.Addr))
s.pprof.BaseContext = func(net.Listener) context.Context {
return ctx
}
group.Go(func() error {
if err := s.pprof.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
s.logger.Error("pprof HTTP server listen", "error", err)
Expand Down

0 comments on commit e3eda83

Please sign in to comment.