Skip to content

Commit

Permalink
Merge pull request #5695 from thaJeztah/fix_TestEventsFormat
Browse files Browse the repository at this point in the history
cli/command/system: TestEventsFormat: set cmd.Args to prevent test-failures
  • Loading branch information
thaJeztah authored Dec 17, 2024
2 parents 0dd6aa8 + 73ff81b commit ecd1622
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cli/command/system/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@ func TestEventsFormat(t *testing.T) {
})
}
tests := []struct {
name, format string
name string
args []string
}{
{
name: "default",
args: []string{},
},
{
name: "json",
format: "json",
name: "json",
args: []string{"--format", "json"},
},
{
name: "json template",
format: "{{ json . }}",
name: "json template",
args: []string{"--format", "{{ json . }}"},
},
{
name: "json action",
format: "{{ json .Action }}",
name: "json action",
args: []string{"--format", "{{ json .Action }}"},
},
}

Expand All @@ -69,9 +71,9 @@ func TestEventsFormat(t *testing.T) {
return messages, errs
}})
cmd := NewEventsCommand(cli)
if tc.format != "" {
cmd.Flags().Set("format", tc.format)
}
cmd.SetArgs(tc.args)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
assert.Check(t, cmd.Execute())
out := cli.OutBuffer().String()
assert.Check(t, golden.String(out, fmt.Sprintf("docker-events-%s.golden", strings.ReplaceAll(tc.name, " ", "-"))))
Expand Down

0 comments on commit ecd1622

Please sign in to comment.