From e3eda839162284f66bf96a9229efbba03b4067b8 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:05:00 +0800 Subject: [PATCH] format --- .golangci.yml | 6 +----- db/config.go | 2 +- db/config_test.go | 20 ++++++++++---------- db/mysql_test.go | 4 ++-- db/sqlite_test.go | 22 +++++++++++----------- pprof/server.go | 3 --- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 0850cf0..2e3b390 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 @@ -97,5 +95,3 @@ linters-settings: - "fmt.Println" - name: import-shadowing disabled: true - - name: cognitive-complexity - disabled: true \ No newline at end of file diff --git a/db/config.go b/db/config.go index 2f5e9ca..dd39e0e 100644 --- a/db/config.go +++ b/db/config.go @@ -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, diff --git a/db/config_test.go b/db/config_test.go index 0d68ad7..42d32c0 100644 --- a/db/config_test.go +++ b/db/config_test.go @@ -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 @@ -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 { diff --git a/db/mysql_test.go b/db/mysql_test.go index e08b818..7344feb 100644 --- a/db/mysql_test.go +++ b/db/mysql_test.go @@ -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, }, { @@ -25,7 +25,7 @@ func TestMysql_CheckSource(t *testing.T) { }, { name: "test3", - source: "coastdao", + source: "my", wantErr: assert.Error, }, } diff --git a/db/sqlite_test.go b/db/sqlite_test.go index 0562a54..ad1f0dc 100644 --- a/db/sqlite_test.go +++ b/db/sqlite_test.go @@ -20,7 +20,7 @@ func TestSqlite_CheckSource(t *testing.T) { }{ { name: "test1", - source: "coastdao.db", + source: "my.db", wantErr: assert.NoError, }, { @@ -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, }, } @@ -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})) @@ -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) { diff --git a/pprof/server.go b/pprof/server.go index e7f7773..1811ee3 100644 --- a/pprof/server.go +++ b/pprof/server.go @@ -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)