From d0a59b13a699b0f245d0058a4567c8a9222068b3 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Fri, 6 May 2022 15:13:46 +0800 Subject: [PATCH] chore: fix deprecated usages (#1871) * add conf documents * chore: use {} instead of () for environment variables * chore: fix deprecated usages * chore: fix unstable tests * chore: show stack on github actions --- core/logx/rotatelogger.go | 2 +- core/logx/rotatelogger_test.go | 7 +------ rest/engine_test.go | 10 +++++----- rest/server_test.go | 8 ++++---- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/core/logx/rotatelogger.go b/core/logx/rotatelogger.go index a7b8ea72..bd31ce7e 100644 --- a/core/logx/rotatelogger.go +++ b/core/logx/rotatelogger.go @@ -292,7 +292,7 @@ func compressLogFile(file string) { start := time.Now() Infof("compressing log file: %s", file) if err := gzipFile(file); err != nil { - Errorf("compress error: %s", err) + ErrorStackf("compress error: %s", err) } else { Infof("compressed log file: %s, took %s", file, time.Since(start)) } diff --git a/core/logx/rotatelogger_test.go b/core/logx/rotatelogger_test.go index 5bb1d58f..a7486d95 100644 --- a/core/logx/rotatelogger_test.go +++ b/core/logx/rotatelogger_test.go @@ -75,10 +75,7 @@ func TestRotateLoggerMayCompressFileTrue(t *testing.T) { logger, err := NewLogger(filename, new(DailyRotateRule), true) assert.Nil(t, err) if len(filename) > 0 { - defer func() { - os.Remove(filename) - os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz") - }() + defer os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz") } logger.maybeCompressFile(filename) _, err = os.Stat(filename) @@ -92,7 +89,6 @@ func TestRotateLoggerRotate(t *testing.T) { assert.Nil(t, err) if len(filename) > 0 { defer func() { - os.Remove(filename) os.Remove(logger.getBackupFilename()) os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz") }() @@ -115,7 +111,6 @@ func TestRotateLoggerWrite(t *testing.T) { assert.Nil(t, err) if len(filename) > 0 { defer func() { - os.Remove(filename) os.Remove(logger.getBackupFilename()) os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz") }() diff --git a/rest/engine_test.go b/rest/engine_test.go index 8b8ff528..a8df1dd9 100644 --- a/rest/engine_test.go +++ b/rest/engine_test.go @@ -146,7 +146,7 @@ Verbose: true for _, yaml := range yamls { for _, route := range routes { var cnf RestConf - assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(yaml), &cnf)) + assert.Nil(t, conf.LoadFromYamlBytes([]byte(yaml), &cnf)) ng := newEngine(cnf) ng.addRoutes(route) ng.use(func(next http.HandlerFunc) http.HandlerFunc { @@ -300,15 +300,15 @@ func TestEngine_notFoundHandlerNotNilWriteHeader(t *testing.T) { type mockedRouter struct{} -func (m mockedRouter) ServeHTTP(writer http.ResponseWriter, request *http.Request) { +func (m mockedRouter) ServeHTTP(_ http.ResponseWriter, _ *http.Request) { } -func (m mockedRouter) Handle(method, path string, handler http.Handler) error { +func (m mockedRouter) Handle(_, _ string, _ http.Handler) error { return errors.New("foo") } -func (m mockedRouter) SetNotFoundHandler(handler http.Handler) { +func (m mockedRouter) SetNotFoundHandler(_ http.Handler) { } -func (m mockedRouter) SetNotAllowedHandler(handler http.Handler) { +func (m mockedRouter) SetNotAllowedHandler(_ http.Handler) { } diff --git a/rest/server_test.go b/rest/server_test.go index c1c655c9..4d4d21be 100644 --- a/rest/server_test.go +++ b/rest/server_test.go @@ -21,7 +21,7 @@ Name: foo Port: 54321 ` var cnf RestConf - assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf)) + assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf)) tests := []struct { c RestConf @@ -271,7 +271,7 @@ Name: foo Port: 54321 ` var cnf RestConf - assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf)) + assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf)) testConfig := &tls.Config{ CipherSuites: []uint16{ @@ -309,7 +309,7 @@ Name: foo Port: 54321 ` var cnf RestConf - assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf)) + assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf)) rt := router.NewRouter() svr, err := NewServer(cnf, WithRouter(rt)) assert.Nil(t, err) @@ -324,7 +324,7 @@ Name: foo Port: 54321 ` var cnf RestConf - assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf)) + assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf)) rt := router.NewRouter() svr, err := NewServer(cnf, WithRouter(rt)) assert.Nil(t, err)