forked from moby/moby
-
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.
pkg/testutils: utility functions to facilitate writing Go tests
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <[email protected]> (github: shykes)
- Loading branch information
Solomon Hykes
committed
Jun 1, 2014
1 parent
4edcbfd
commit ca231b3
Showing
4 changed files
with
28 additions
and
15 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 @@ | ||
Solomon Hykes <[email protected]> (@shykes) |
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,2 @@ | ||
`testutils` is a collection of utility functions to facilitate the writing | ||
of tests. It is used in various places by the Docker test suite. |
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,23 @@ | ||
package testutils | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
// Timeout calls f and waits for 100ms for it to complete. | ||
// If it doesn't, it causes the tests to fail. | ||
// t must be a valid testing context. | ||
func Timeout(t *testing.T, f func()) { | ||
onTimeout := time.After(100 * time.Millisecond) | ||
onDone := make(chan bool) | ||
go func() { | ||
f() | ||
close(onDone) | ||
}() | ||
select { | ||
case <-onTimeout: | ||
t.Fatalf("timeout") | ||
case <-onDone: | ||
} | ||
} |