Skip to content

Commit

Permalink
Ensure args match verbs in ConsoleLogger (#877)
Browse files Browse the repository at this point in the history
Fix the format call for `Supplied` event.

Previously, `\n%!(EXTRA string=)` was appended to `SUPPLY` logs when
`ModuleName` was empty.

Add tests to ensure format string contains the same number of verbs as
there are arguments when logging an `Event` using `ConsoleLogger` for
all relevant event types,

Module info was added to fxevent in #863.
  • Loading branch information
jkanywhere committed May 4, 2022
1 parent 81f070e commit c8d593a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fxevent/console.go
Expand Up @@ -65,7 +65,7 @@ func (l *ConsoleLogger) LogEvent(event Event) {
} else if e.ModuleName != "" {
l.logf("SUPPLY\t%v from module %q", e.TypeName, e.ModuleName)
} else {
l.logf("SUPPLY\t%v", e.TypeName, e.ModuleName)
l.logf("SUPPLY\t%v", e.TypeName)
}
case *Provided:
for _, rtype := range e.OutputTypeNames {
Expand Down
36 changes: 36 additions & 0 deletions fxevent/console_test.go
Expand Up @@ -137,6 +137,11 @@ func TestConsoleLogger(t *testing.T) {
},
{
name: "Supplied",
give: &Supplied{TypeName: "*bytes.Buffer"},
want: "[Fx] SUPPLY *bytes.Buffer\n",
},
{
name: "Supplied with module",
give: &Supplied{TypeName: "*bytes.Buffer", ModuleName: "myModule"},
want: "[Fx] SUPPLY *bytes.Buffer from module \"myModule\"\n",
},
Expand All @@ -152,6 +157,14 @@ func TestConsoleLogger(t *testing.T) {
},
{
name: "Provided",
give: &Provided{
ConstructorName: "bytes.NewBuffer()",
OutputTypeNames: []string{"*bytes.Buffer"},
},
want: "[Fx] PROVIDE *bytes.Buffer <= bytes.NewBuffer()\n",
},
{
name: "Provided with module",
give: &Provided{
ConstructorName: "bytes.NewBuffer()",
ModuleName: "myModule",
Expand All @@ -161,6 +174,13 @@ func TestConsoleLogger(t *testing.T) {
},
{
name: "Replaced",
give: &Replaced{
OutputTypeNames: []string{"*bytes.Buffer"},
},
want: "[Fx] REPLACE *bytes.Buffer\n",
},
{
name: "Replaced with module",
give: &Replaced{
ModuleName: "myModule",
OutputTypeNames: []string{"*bytes.Buffer"},
Expand All @@ -174,6 +194,14 @@ func TestConsoleLogger(t *testing.T) {
},
{
name: "Decorated",
give: &Decorated{
DecoratorName: "bytes.NewBuffer()",
OutputTypeNames: []string{"*bytes.Buffer"},
},
want: "[Fx] DECORATE *bytes.Buffer <= bytes.NewBuffer()\n",
},
{
name: "Decorated with module",
give: &Decorated{
DecoratorName: "bytes.NewBuffer()",
ModuleName: "myModule",
Expand All @@ -196,6 +224,14 @@ func TestConsoleLogger(t *testing.T) {
give: &Invoking{FunctionName: "bytes.NewBuffer()"},
want: "[Fx] INVOKE bytes.NewBuffer()\n",
},
{
name: "Invoking with module",
give: &Invoking{
FunctionName: "bytes.NewBuffer()",
ModuleName: "myModule",
},
want: "[Fx] INVOKE bytes.NewBuffer() from module \"myModule\"\n",
},
{
name: "Invoked/Error",
give: &Invoked{
Expand Down

0 comments on commit c8d593a

Please sign in to comment.