This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from mjs/writer-tags
writer: Include InfluxDB details in metrics tags
- Loading branch information
Showing
4 changed files
with
93 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package spouttest | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// AssertRecv checks that a specific string has been received from a | ||
// channel. The check times out after LongWait. | ||
func AssertRecv(t *testing.T, ch <-chan string, label, expected string) { | ||
expected = stripLeadingNL(expected) | ||
|
||
select { | ||
case received := <-ch: | ||
assert.Equal(t, expected, received) | ||
case <-time.After(LongWait): | ||
t.Fatalf("timed out waiting for %s", label) | ||
} | ||
} | ||
|
||
// AssertRecvMulti checks that a specific string has been received | ||
// from a channel. The channel will be read multiple times if | ||
// required. The check times out after LongWait. | ||
func AssertRecvMulti(t *testing.T, ch <-chan string, label, expected string) { | ||
expected = stripLeadingNL(expected) | ||
|
||
var received string | ||
timeout := time.After(LongWait) | ||
for { | ||
select { | ||
case received = <-ch: | ||
if expected == received { | ||
return | ||
} | ||
case <-timeout: | ||
t.Fatalf("timed out waiting for %s. last received: %q", label, received) | ||
} | ||
} | ||
} | ||
|
||
func stripLeadingNL(s string) string { | ||
// This allows long `expected` strings to be formatted nicely in | ||
// the caller. | ||
if strings.HasPrefix(s, "\n") { | ||
return s[1:] | ||
} | ||
return s | ||
} |
This file contains 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 characters
This file contains 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 characters