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

Add more Fx.Decorate tests #846

Merged
merged 3 commits into from Feb 22, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions decorate_test.go
Expand Up @@ -213,6 +213,54 @@ func TestDecorateSuccess(t *testing.T) {
)
defer app.RequireStart().RequireStop()
})

t.Run("transitive decoration", func(t *testing.T) {
type Config struct {
Scope string
}
type Logger struct {
Cfg *Config
}
app := fxtest.New(t,
fx.Provide(func() *Config { return &Config{Scope: "root"} }),
fx.Module("child",
fx.Decorate(func() *Config { return &Config{Scope: "child"} }),
fx.Provide(func(cfg *Config) *Logger { return &Logger{Cfg: cfg} }),
fx.Invoke(func(l *Logger) {
assert.Equal(t, "child", l.Cfg.Scope)
}),
),
)
defer app.RequireStart().RequireStop()
})

t.Run("transitive and scoped decorations", func(t *testing.T) {
type Config struct {
Scope string
}
type Logger struct {
Cfg *Config
}
app := fxtest.New(t,
fx.Provide(func() *Config {
return &Config{Scope: "root"}
}),
fx.Provide(func(cfg *Config) *Logger {
return &Logger{Cfg: &Config{
Scope: cfg.Scope + " logger",
}}
}),
fx.Module("child",
fx.Decorate(func() *Config {
return &Config{Scope: "child"}
}),
fx.Invoke(func(l *Logger) {
assert.Equal(t, "child logger", l.Cfg.Scope)
}),
Comment on lines +253 to +259
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

I didn't think of this one. This is nice.

),
)
defer app.RequireStart().RequireStop()
})
}

func TestDecorateFailure(t *testing.T) {
Expand Down