From 6f2458c40ce1772f47f3dada8eb77fa349812a2a Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 9 May 2014 21:11:24 -0700 Subject: [PATCH 1/3] pkg/testutils: utility functions to facilitate writing Go tests Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- testutils/MAINTAINERS | 1 + testutils/README.md | 2 ++ testutils/testutils.go | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 testutils/MAINTAINERS create mode 100644 testutils/README.md create mode 100644 testutils/testutils.go diff --git a/testutils/MAINTAINERS b/testutils/MAINTAINERS new file mode 100644 index 0000000..012d27a --- /dev/null +++ b/testutils/MAINTAINERS @@ -0,0 +1 @@ +Solomon Hykes (@shykes) diff --git a/testutils/README.md b/testutils/README.md new file mode 100644 index 0000000..a208a90 --- /dev/null +++ b/testutils/README.md @@ -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. diff --git a/testutils/testutils.go b/testutils/testutils.go new file mode 100644 index 0000000..4655e58 --- /dev/null +++ b/testutils/testutils.go @@ -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: + } +} From ab3832aabc828714b9155d9871a6cb5535ce5a0b Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 2 Jun 2014 07:01:17 +0000 Subject: [PATCH 2/3] Add Cristian as maintainer to pkg/testutils Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- testutils/MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/testutils/MAINTAINERS b/testutils/MAINTAINERS index 012d27a..1c41a67 100644 --- a/testutils/MAINTAINERS +++ b/testutils/MAINTAINERS @@ -1 +1,2 @@ Solomon Hykes (@shykes) +Cristian Staretu (github: unclejack) From 1b7845224d17e1aa64c4abea28cab70bdfad8eaa Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 2 Jun 2014 07:05:06 +0000 Subject: [PATCH 3/3] Fix format in maintainers files Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- testutils/MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutils/MAINTAINERS b/testutils/MAINTAINERS index 1c41a67..f2e8c52 100644 --- a/testutils/MAINTAINERS +++ b/testutils/MAINTAINERS @@ -1,2 +1,2 @@ Solomon Hykes (@shykes) -Cristian Staretu (github: unclejack) +Cristian Staretu (@unclejack)