Skip to content

Commit

Permalink
Merge pull request #279 from thaJeztah/poll_msgAndArgs
Browse files Browse the repository at this point in the history
poll: Continue(): use format.Message for formatting
  • Loading branch information
dnephin authored Aug 29, 2024
2 parents 631f6c8 + 7f28766 commit db81ec0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion poll/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/internal/assert"
"gotest.tools/v3/internal/format"
)

// TestingT is the subset of [testing.T] used by [WaitOn]
Expand Down Expand Up @@ -90,7 +91,7 @@ func (r result) Error() error {
// polling. The message text will be used as the failure message if the timeout
// is reached.
func Continue(message string, args ...interface{}) Result {
return result{message: fmt.Sprintf(message, args...)}
return result{message: format.Message(append([]interface{}{message}, args...)...)}
}

// Success returns a [Result] where Done() returns true, which indicates to [WaitOn]
Expand Down
27 changes: 27 additions & 0 deletions poll/poll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ func (t *fakeT) Log(args ...interface{}) {}

func (t *fakeT) Logf(format string, args ...interface{}) {}

func TestContinueMessage(t *testing.T) {
tests := []struct {
msg string
args []interface{}
expected string
}{
{
msg: "literal message",
expected: "literal message",
},
{
msg: "templated %s",
args: []interface{}{"message"},
expected: "templated message",
},
{
msg: "literal message with percentage symbols (%USERPROFILE%)",
expected: "literal message with percentage symbols (%USERPROFILE%)",
},
}

for _, tc := range tests {
actual := Continue(tc.msg, tc.args...).Message()
assert.Check(t, cmp.Equal(tc.expected, actual))
}
}

func TestWaitOn(t *testing.T) {
counter := 0
end := 4
Expand Down

0 comments on commit db81ec0

Please sign in to comment.