Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: add fatal method for logger(config-enhance branch) #1482

Merged
merged 2 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add test for logger fatal & fatalf
  • Loading branch information
cjphaha committed Sep 25, 2021
commit e7b18c02819f7c88840f2a7d0cc85d7bb7ce7ab7
14 changes: 14 additions & 0 deletions config/logger_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@
package config

import (
"os"
"testing"
)

import (
"bou.ke/monkey"
"github.com/stretchr/testify/assert"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
)

func fakeExit(int) {
panic("os.Exit called")
}

func TestLoggerInit(t *testing.T) {
t.Run("empty use default", func(t *testing.T) {
err := Load(WithPath("./testdata/config/logger/empty_log.yaml"))
Expand All @@ -38,6 +44,14 @@ func TestLoggerInit(t *testing.T) {
assert.NotNil(t, loggerConfig)
assert.Equal(t, []string{"stderr"}, loggerConfig.ZapConfig.OutputPaths)
logger.Info("hello")
patch := monkey.Patch(os.Exit, fakeExit)
defer patch.Unpatch()
assert.PanicsWithValue(t, "os.Exit called", func() {
logger.Fatalf("%s", "error")
}, "os.Exit was not called")
assert.PanicsWithValue(t, "os.Exit called", func() {
logger.Fatal("error")
}, "os.Exit was not called")
})

t.Run("use config", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module dubbo.apache.org/dubbo-go/v3
go 1.15

require (
bou.ke/monkey v1.0.2
github.com/RoaringBitmap/roaring v0.7.1
github.com/Workiva/go-datastructures v1.0.52
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8=
bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI=
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down