Last active
March 15, 2022 21:13
-
-
Save jbreiding/125320415f38b2db7e845925dd1beec0 to your computer and use it in GitHub Desktop.
Revisions
-
jbreiding revised this gist
Mar 15, 2022 . 2 changed files with 35 additions and 36 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,16 +41,6 @@ func NewServiceNameLogger(name ServiceName, l *zap.Logger, lc fx.Lifecycle) *Ser return &snl } func TestXxx(t *testing.T) { t.Run("oops", func(t *testing.T) { test3 := fx.Module( @@ -59,6 +49,7 @@ func TestXxx(t *testing.T) { return ServiceName("test3") }), fx.Decorate(func(s ServiceName, l *zap.Logger) *zap.Logger { assert.Equal(t, "test3", string(s)) return l.With(zap.String("name", string(s))) }), fx.Decorate(NewServiceNameLogger), @@ -75,6 +66,7 @@ func TestXxx(t *testing.T) { return ServiceName("test2") }), fx.Decorate(func(s ServiceName, l *zap.Logger) *zap.Logger { assert.Equal(t, "test2", string(s)) return l.With(zap.String("name", string(s))) }), fx.Decorate(NewServiceNameLogger), @@ -86,7 +78,14 @@ func TestXxx(t *testing.T) { app := fxtest.New(t, test2, fx.Provide(func() ServiceName { return ServiceName("test1") }), fx.Provide(func(s ServiceName) (*zap.Logger, error) { assert.Equal(t, "test1", string(s)) return zap.NewDevelopment() }), fx.Provide(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger) { assert.Equal(t, "test1", string(snl.Name)) snl.LogServiceName() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ === RUN TestXxx === RUN TestXxx/oops writer.go:40: [Fx] PROVIDE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.7() writer.go:40: [Fx] PROVIDE *zap.Logger <= go.temporal.io/server/tests.TestXxx.func1.8() writer.go:40: [Fx] PROVIDE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] PROVIDE fx.Lifecycle <= go.uber.org/fx.New.func1() writer.go:40: [Fx] PROVIDE fx.Shutdowner <= go.uber.org/fx.(*App).shutdowner-fm() @@ -13,11 +13,11 @@ writer.go:40: [Fx] DECORATE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.1() writer.go:40: [Fx] DECORATE *zap.Logger <= go.temporal.io/server/tests.TestXxx.func1.2() writer.go:40: [Fx] DECORATE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.9() 2022-03-15T21:13:09.891Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.6() fx_module_test.go:74: Error Trace: fx_module_test.go:74 value.go:556 value.go:339 container.go:220 @@ -28,7 +28,7 @@ module.go:159 app.go:534 app.go:44 fx_module_test.go:79 Error: Not equal: expected: "test2" actual : "test1" @@ -40,10 +40,10 @@ -test2 +test1 Test: TestXxx/oops 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.3() fx_module_test.go:57: Error Trace: fx_module_test.go:57 value.go:556 value.go:339 container.go:220 @@ -55,7 +55,7 @@ module.go:159 app.go:534 app.go:44 fx_module_test.go:79 Error: Not equal: expected: "test3" actual : "test2" @@ -67,28 +67,28 @@ -test3 +test2 Test: TestXxx/oops 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"name": "test2", "svc_name": "test2"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 6.292µs writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 2.834µs writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"name": "test2", "svc_name": "test2"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 2.209µs writer.go:40: [Fx] RUNNING writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"name": "test2", "svc_name": "test2"} writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 5.084µs writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 2.125µs writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:13:09.892Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 2.667µs --- FAIL: TestXxx (0.00s) --- FAIL: TestXxx/oops (0.00s) FAIL FAIL go.temporal.io/server/tests 0.021s FAIL -
jbreiding revised this gist
Mar 15, 2022 . 2 changed files with 93 additions and 52 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,32 +2,29 @@ package tests import ( "context" "testing" "github.com/stretchr/testify/assert" "go.uber.org/fx" "go.uber.org/fx/fxtest" "go.uber.org/zap" ) type ServiceName string type ServiceNameLogger struct { Name ServiceName Logger *zap.Logger } func (s *ServiceNameLogger) LogServiceName() { s.Logger.Info("LogServiceName ", zap.String("svc_name", string(s.Name))) } func NewServiceNameLogger(name ServiceName, l *zap.Logger, lc fx.Lifecycle) *ServiceNameLogger { snl := ServiceNameLogger{ Name: name, Logger: l, } lc.Append(fx.Hook{ @@ -48,14 +45,10 @@ var Module = fx.Options( fx.Provide(func() ServiceName { return ServiceName("test1") }), fx.Provide(func(s ServiceName) (*zap.Logger, error) { return zap.NewDevelopment() }), fx.Provide(NewServiceNameLogger), ) func TestXxx(t *testing.T) { @@ -65,12 +58,12 @@ func TestXxx(t *testing.T) { fx.Decorate(func() ServiceName { return ServiceName("test3") }), fx.Decorate(func(s ServiceName, l *zap.Logger) *zap.Logger { return l.With(zap.String("name", string(s))) }), fx.Decorate(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger) { assert.Equal(t, "test3", string(snl.Name)) snl.LogServiceName() }), ) @@ -81,19 +74,23 @@ func TestXxx(t *testing.T) { fx.Decorate(func() ServiceName { return ServiceName("test2") }), fx.Decorate(func(s ServiceName, l *zap.Logger) *zap.Logger { return l.With(zap.String("name", string(s))) }), fx.Decorate(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger) { assert.Equal(t, "test2", string(snl.Name)) snl.LogServiceName() }), ) app := fxtest.New(t, test2, Module, fx.Invoke(func(snl *ServiceNameLogger) { assert.Equal(t, "test1", string(snl.Name)) snl.LogServiceName() }), ) defer app.RequireStart().RequireStop() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,50 +1,94 @@ === RUN TestXxx === RUN TestXxx/oops writer.go:40: [Fx] PROVIDE tests.ServiceName <= go.temporal.io/server/tests.glob..func1() writer.go:40: [Fx] PROVIDE *zap.Logger <= go.temporal.io/server/tests.glob..func2() writer.go:40: [Fx] PROVIDE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] PROVIDE fx.Lifecycle <= go.uber.org/fx.New.func1() writer.go:40: [Fx] PROVIDE fx.Shutdowner <= go.uber.org/fx.(*App).shutdowner-fm() writer.go:40: [Fx] PROVIDE fx.DotGraph <= go.uber.org/fx.(*App).dotGraph-fm() writer.go:40: [Fx] LOGGER Initialized custom logger from go.uber.org/fx/fxtest.New.func1() writer.go:40: [Fx] DECORATE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.4() writer.go:40: [Fx] DECORATE *zap.Logger <= go.temporal.io/server/tests.TestXxx.func1.5() writer.go:40: [Fx] DECORATE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] DECORATE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.1() writer.go:40: [Fx] DECORATE *zap.Logger <= go.temporal.io/server/tests.TestXxx.func1.2() writer.go:40: [Fx] DECORATE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.7() 2022-03-15T21:10:45.989Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.6() fx_module_test.go:82: Error Trace: fx_module_test.go:82 value.go:556 value.go:339 container.go:220 invoke.go:92 invoke.go:93 module.go:171 module.go:153 module.go:159 app.go:534 app.go:44 fx_module_test.go:87 Error: Not equal: expected: "test2" actual : "test1" Diff: --- Expected +++ Actual @@ -1 +1 @@ -test2 +test1 Test: TestXxx/oops 2022-03-15T21:10:45.989Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.3() fx_module_test.go:66: Error Trace: fx_module_test.go:66 value.go:556 value.go:339 container.go:220 invoke.go:92 invoke.go:93 module.go:171 module.go:153 module.go:159 module.go:159 app.go:534 app.go:44 fx_module_test.go:87 Error: Not equal: expected: "test3" actual : "test2" Diff: --- Expected +++ Actual @@ -1 +1 @@ -test3 +test2 Test: TestXxx/oops 2022-03-15T21:10:45.989Z INFO tests/fx_module_test.go:21 LogServiceName {"name": "test2", "svc_name": "test2"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:10:45.989Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 2.875µs writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:10:45.989Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 2.042µs writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:10:45.989Z INFO tests/fx_module_test.go:21 LogServiceName {"name": "test2", "svc_name": "test2"} writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 1.917µs writer.go:40: [Fx] RUNNING writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:10:45.989Z INFO tests/fx_module_test.go:21 LogServiceName {"name": "test2", "svc_name": "test2"} writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 2.167µs writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:10:45.990Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 1.958µs writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) 2022-03-15T21:10:45.990Z INFO tests/fx_module_test.go:21 LogServiceName {"svc_name": "test1"} writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 1.875µs --- FAIL: TestXxx (0.00s) --- FAIL: TestXxx/oops (0.00s) FAIL FAIL go.temporal.io/server/tests 0.034s FAIL -
jbreiding revised this gist
Mar 15, 2022 . 2 changed files with 24 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,8 @@ var Module = fx.Options( return log.New(os.Stdout, fmt.Sprintf("%s: ", s), 0) }), fx.Provide(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger, logger *log.Logger) { logger.Print("test1") snl.LogServiceName() }), ) @@ -64,11 +65,12 @@ func TestXxx(t *testing.T) { fx.Decorate(func() ServiceName { return ServiceName("test3") }), fx.Decorate(func(s ServiceName) *log.Logger { return log.New(os.Stdout, fmt.Sprintf("%s: ", s), 0) }), fx.Decorate(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger, logger *log.Logger) { logger.Print("test3") snl.LogServiceName() }), ) @@ -79,11 +81,12 @@ func TestXxx(t *testing.T) { fx.Decorate(func() ServiceName { return ServiceName("test2") }), fx.Decorate(func(s ServiceName) *log.Logger { return log.New(os.Stdout, fmt.Sprintf("%s: ", s), 0) }), fx.Decorate(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger, logger *log.Logger) { logger.Print("test2") snl.LogServiceName() }), ) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ === RUN TestXxx === RUN TestXxx/oops writer.go:40: [Fx] PROVIDE tests.ServiceName <= go.temporal.io/server/tests.glob..func1() @@ -9,40 +8,43 @@ writer.go:40: [Fx] PROVIDE fx.DotGraph <= go.uber.org/fx.(*App).dotGraph-fm() writer.go:40: [Fx] LOGGER Initialized custom logger from go.uber.org/fx/fxtest.New.func1() writer.go:40: [Fx] DECORATE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.4() writer.go:40: [Fx] DECORATE *log.Logger <= go.temporal.io/server/tests.TestXxx.func1.5() writer.go:40: [Fx] DECORATE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] DECORATE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.1() writer.go:40: [Fx] DECORATE *log.Logger <= go.temporal.io/server/tests.TestXxx.func1.2() writer.go:40: [Fx] DECORATE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.glob..func3() test1: NewServiceNameLogger test1 test1: test1 test1: ServiceName test1 writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.6() test1: NewServiceNameLogger test1 test1: test2 test1: ServiceName test1 writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.3() test1: NewServiceNameLogger test2 test2: test3 test1: ServiceName test2 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 3.5µs writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 875ns writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test2 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 666ns writer.go:40: [Fx] RUNNING writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test2 writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 792ns writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 541ns writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 541ns --- PASS: TestXxx (0.00s) --- PASS: TestXxx/oops (0.00s) PASS ok go.temporal.io/server/tests (cached) -
jbreiding revised this gist
Mar 15, 2022 . 1 changed file with 48 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ //go test -v -timeout 20m -run ^TestXxx$ go.temporal.io/server/tests === RUN TestXxx === RUN TestXxx/oops writer.go:40: [Fx] PROVIDE tests.ServiceName <= go.temporal.io/server/tests.glob..func1() writer.go:40: [Fx] PROVIDE *log.Logger <= go.temporal.io/server/tests.glob..func2() writer.go:40: [Fx] PROVIDE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] PROVIDE fx.Lifecycle <= go.uber.org/fx.New.func1() writer.go:40: [Fx] PROVIDE fx.Shutdowner <= go.uber.org/fx.(*App).shutdowner-fm() writer.go:40: [Fx] PROVIDE fx.DotGraph <= go.uber.org/fx.(*App).dotGraph-fm() writer.go:40: [Fx] LOGGER Initialized custom logger from go.uber.org/fx/fxtest.New.func1() writer.go:40: [Fx] DECORATE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.4() writer.go:40: [Fx] DECORATE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] DECORATE *log.Logger <= go.temporal.io/server/tests.TestXxx.func1.5() writer.go:40: [Fx] DECORATE tests.ServiceName <= go.temporal.io/server/tests.TestXxx.func1.1() writer.go:40: [Fx] DECORATE *tests.ServiceNameLogger <= go.temporal.io/server/tests.NewServiceNameLogger() writer.go:40: [Fx] DECORATE *log.Logger <= go.temporal.io/server/tests.TestXxx.func1.2() writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.glob..func3() test1: NewServiceNameLogger test1 test1: ServiceName test1 writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.6() test1: NewServiceNameLogger test1 test1: ServiceName test1 writer.go:40: [Fx] INVOKE go.temporal.io/server/tests.TestXxx.func1.3() test2: NewServiceNameLogger test2 test2: ServiceName test2 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 875ns writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 583ns writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test2: ServiceName test2 writer.go:40: [Fx] HOOK OnStart go.temporal.io/server/tests.NewServiceNameLogger.func1() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 542ns writer.go:40: [Fx] RUNNING writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test2: ServiceName test2 writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 667ns writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 542ns writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() executing (caller: go.temporal.io/server/tests.NewServiceNameLogger) test1: ServiceName test1 writer.go:40: [Fx] HOOK OnStop go.temporal.io/server/tests.NewServiceNameLogger.func2() called by go.temporal.io/server/tests.NewServiceNameLogger ran successfully in 500ns --- PASS: TestXxx (0.00s) --- PASS: TestXxx/oops (0.00s) PASS ok go.temporal.io/server/tests 0.021s -
jbreiding revised this gist
Mar 15, 2022 . 1 changed file with 0 additions and 33 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import ( "os" "testing" "go.uber.org/fx" "go.uber.org/fx/fxtest" ) @@ -97,35 +96,3 @@ func TestXxx(t *testing.T) { defer app.RequireStart().RequireStop() }) } -
jbreiding revised this gist
Mar 15, 2022 . 1 changed file with 10 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package tests import ( "context" "fmt" "log" "os" "testing" @@ -45,11 +46,11 @@ func NewServiceNameLogger(name ServiceName, logger *log.Logger, lc fx.Lifecycle) } var Module = fx.Options( fx.Provide(func() ServiceName { return ServiceName("test1") }), fx.Provide(func(s ServiceName) *log.Logger { return log.New(os.Stdout, fmt.Sprintf("%s: ", s), 0) }), fx.Provide(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger) { @@ -61,12 +62,12 @@ func TestXxx(t *testing.T) { t.Run("oops", func(t *testing.T) { test3 := fx.Module( "test3", fx.Decorate(func() ServiceName { return ServiceName("test3") }), fx.Decorate(NewServiceNameLogger), fx.Decorate(func(s ServiceName) *log.Logger { return log.New(os.Stdout, fmt.Sprintf("%s: ", s), 0) }), fx.Invoke(func(snl *ServiceNameLogger) { snl.LogServiceName() @@ -76,12 +77,12 @@ func TestXxx(t *testing.T) { test2 := fx.Module( "test2", test3, fx.Decorate(func() ServiceName { return ServiceName("test2") }), fx.Decorate(NewServiceNameLogger), fx.Decorate(func(s ServiceName) *log.Logger { return log.New(os.Stdout, fmt.Sprintf("%s: ", s), 0) }), fx.Invoke(func(snl *ServiceNameLogger) { snl.LogServiceName() -
jbreiding revised this gist
Mar 15, 2022 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ type ServiceNameLogger struct { } func (s *ServiceNameLogger) LogServiceName() { s.Logger.Println("ServiceName ", s.Name) } func NewServiceNameLogger(name ServiceName, logger *log.Logger, lc fx.Lifecycle) *ServiceNameLogger { @@ -46,7 +46,6 @@ func NewServiceNameLogger(name ServiceName, logger *log.Logger, lc fx.Lifecycle) var Module = fx.Options( fx.Provide(func(logger *log.Logger) ServiceName { return ServiceName("test1") }), fx.Provide(func() *log.Logger { @@ -63,7 +62,6 @@ func TestXxx(t *testing.T) { test3 := fx.Module( "test3", fx.Decorate(func(logger *log.Logger) ServiceName { return ServiceName("test3") }), fx.Decorate(NewServiceNameLogger), @@ -79,7 +77,6 @@ func TestXxx(t *testing.T) { "test2", test3, fx.Decorate(func(logger *log.Logger) ServiceName { return ServiceName("test2") }), fx.Decorate(NewServiceNameLogger), -
jbreiding revised this gist
Mar 15, 2022 . 1 changed file with 18 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,26 +44,20 @@ func NewServiceNameLogger(name ServiceName, logger *log.Logger, lc fx.Lifecycle) return &snl } var Module = fx.Options( fx.Provide(func(logger *log.Logger) ServiceName { logger.Print("test1 servicename") return ServiceName("test1") }), fx.Provide(func() *log.Logger { return log.New(os.Stdout, "", 0) }), fx.Provide(NewServiceNameLogger), fx.Invoke(func(snl *ServiceNameLogger) { snl.LogServiceName() }), ) func TestXxx(t *testing.T) { t.Run("oops", func(t *testing.T) { test3 := fx.Module( @@ -73,8 +67,12 @@ func TestXxx(t *testing.T) { return ServiceName("test3") }), fx.Decorate(NewServiceNameLogger), fx.Decorate(func() *log.Logger { return log.New(os.Stdout, "", 0) }), fx.Invoke(func(snl *ServiceNameLogger) { snl.LogServiceName() }), ) test2 := fx.Module( @@ -85,8 +83,12 @@ func TestXxx(t *testing.T) { return ServiceName("test2") }), fx.Decorate(NewServiceNameLogger), fx.Decorate(func() *log.Logger { return log.New(os.Stdout, "", 0) }), fx.Invoke(func(snl *ServiceNameLogger) { snl.LogServiceName() }), ) app := fxtest.New(t, -
jbreiding created this gist
Mar 15, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,131 @@ package tests import ( "context" "log" "os" "testing" "github.com/stretchr/testify/assert" "go.uber.org/fx" "go.uber.org/fx/fxtest" ) type ServiceName string type ServiceNameLogger struct { Name ServiceName Logger *log.Logger } func (s *ServiceNameLogger) LogServiceName() { s.Logger.Println(s.Name) } func NewServiceNameLogger(name ServiceName, logger *log.Logger, lc fx.Lifecycle) *ServiceNameLogger { logger.Print("NewServiceNameLogger ", name) snl := ServiceNameLogger{ Name: name, Logger: logger, } lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { snl.LogServiceName() return nil }, OnStop: func(ctx context.Context) error { snl.LogServiceName() return nil }, }) return &snl } func NewLogger() *log.Logger { logger := log.New(os.Stdout, "", 0) logger.Print("Executing NewLogger.") return logger } var Module = fx.Options( fx.Provide(func(logger *log.Logger) ServiceName { logger.Print("test1 servicename") return ServiceName("test1") }), fx.Provide(NewLogger), fx.Provide(NewServiceNameLogger), fx.Invoke(Get), ) func Get(snl *ServiceNameLogger) { snl.LogServiceName() } func TestXxx(t *testing.T) { t.Run("oops", func(t *testing.T) { test3 := fx.Module( "test3", fx.Decorate(func(logger *log.Logger) ServiceName { logger.Print("test3 servicename") return ServiceName("test3") }), fx.Decorate(NewServiceNameLogger), fx.Decorate(NewLogger), fx.Invoke(Get), ) test2 := fx.Module( "test2", test3, fx.Decorate(func(logger *log.Logger) ServiceName { logger.Print("test2 servicename") return ServiceName("test2") }), fx.Decorate(NewServiceNameLogger), fx.Decorate(NewLogger), fx.Invoke(Get), ) app := fxtest.New(t, test2, Module, ) defer app.RequireStart().RequireStop() }) } func TestDecorateSuccess(t *testing.T) { type Logger struct { Name string } t.Run("objects provided by other modules are decorated", func(t *testing.T) { redis := fx.Module("redis", fx.Provide(func() *Logger { return &Logger{Name: "redis"} }), ) testRedis := fx.Module("testRedis", redis, fx.Decorate(func() *Logger { return &Logger{Name: "testRedis"} }), fx.Invoke(func(l *Logger) { assert.Equal(t, "testRedis", l.Name) }), ) app := fxtest.New(t, testRedis, fx.Invoke(func(l *Logger) { assert.Equal(t, "redis", l.Name) }), ) defer app.RequireStart().RequireStop() }) }