-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nathan Lowe
committed
Dec 5, 2019
1 parent
f4d06fb
commit ebb267b
Showing
5 changed files
with
67 additions
and
53 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
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
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,48 @@ | ||
package output | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/magiconair/properties/assert" | ||
) | ||
|
||
func Each(outputs <-chan int, cb func(int)) *sync.WaitGroup { | ||
wg := &sync.WaitGroup{} | ||
|
||
go func() { | ||
for code := range outputs { | ||
cb(code) | ||
} | ||
|
||
wg.Done() | ||
}() | ||
|
||
return wg | ||
} | ||
|
||
func Expect(t *testing.T, outputs <-chan int, expected ...int) *sync.WaitGroup { | ||
wg := &sync.WaitGroup{} | ||
wg.Add(1) | ||
|
||
go func() { | ||
for v := range outputs { | ||
assert.Equal(t, expected[0], v) | ||
} | ||
wg.Done() | ||
}() | ||
|
||
return wg | ||
} | ||
|
||
func Single(outputs <-chan int, result *int) *sync.WaitGroup { | ||
wg := &sync.WaitGroup{} | ||
wg.Add(1) | ||
|
||
go func() { | ||
*result = <-outputs | ||
wg.Done() | ||
}() | ||
|
||
return wg | ||
} |