Refactor setupRemotePluginServer() to be a helper, and to spin up a test-
server for each test instead of sharing the same instance between tests.
This allows the tests to be run in parallel without stepping on each-other's
toes (tearing down the server).
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -18,21 +18,15 @@ import ( |
| 18 | 18 |
is "gotest.tools/v3/assert/cmp" |
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 |
-var ( |
|
| 22 |
- mux *http.ServeMux |
|
| 23 |
- server *httptest.Server |
|
| 24 |
-) |
|
| 25 |
- |
|
| 26 |
-func setupRemotePluginServer() string {
|
|
| 21 |
+func setupRemotePluginServer(t *testing.T) (mux *http.ServeMux, addr string) {
|
|
| 22 |
+ t.Helper() |
|
| 27 | 23 |
mux = http.NewServeMux() |
| 28 |
- server = httptest.NewServer(mux) |
|
| 29 |
- return server.URL |
|
| 30 |
-} |
|
| 31 |
- |
|
| 32 |
-func teardownRemotePluginServer() {
|
|
| 33 |
- if server != nil {
|
|
| 24 |
+ server := httptest.NewServer(mux) |
|
| 25 |
+ t.Logf("started remote plugin server listening on: %s", server.URL)
|
|
| 26 |
+ t.Cleanup(func() {
|
|
| 34 | 27 |
server.Close() |
| 35 |
- } |
|
| 28 |
+ }) |
|
| 29 |
+ return mux, server.URL |
|
| 36 | 30 |
} |
| 37 | 31 |
|
| 38 | 32 |
func TestFailedConnection(t *testing.T) {
|
| ... | ... |
@@ -44,8 +38,7 @@ func TestFailedConnection(t *testing.T) {
|
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 | 46 |
func TestFailOnce(t *testing.T) {
|
| 47 |
- addr := setupRemotePluginServer() |
|
| 48 |
- defer teardownRemotePluginServer() |
|
| 47 |
+ mux, addr := setupRemotePluginServer(t) |
|
| 49 | 48 |
|
| 50 | 49 |
failed := false |
| 51 | 50 |
mux.HandleFunc("/Test.FailOnce", func(w http.ResponseWriter, r *http.Request) {
|
| ... | ... |
@@ -64,8 +57,7 @@ func TestFailOnce(t *testing.T) {
|
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 | 66 |
func TestEchoInputOutput(t *testing.T) {
|
| 67 |
- addr := setupRemotePluginServer() |
|
| 68 |
- defer teardownRemotePluginServer() |
|
| 67 |
+ mux, addr := setupRemotePluginServer(t) |
|
| 69 | 68 |
|
| 70 | 69 |
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
| 71 | 70 |
|
| ... | ... |
@@ -157,8 +149,7 @@ func TestClientScheme(t *testing.T) {
|
| 157 | 157 |
} |
| 158 | 158 |
|
| 159 | 159 |
func TestNewClientWithTimeout(t *testing.T) {
|
| 160 |
- addr := setupRemotePluginServer() |
|
| 161 |
- defer teardownRemotePluginServer() |
|
| 160 |
+ mux, addr := setupRemotePluginServer(t) |
|
| 162 | 161 |
|
| 163 | 162 |
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
| 164 | 163 |
|
| ... | ... |
@@ -178,8 +169,7 @@ func TestNewClientWithTimeout(t *testing.T) {
|
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
func TestClientStream(t *testing.T) {
|
| 181 |
- addr := setupRemotePluginServer() |
|
| 182 |
- defer teardownRemotePluginServer() |
|
| 181 |
+ mux, addr := setupRemotePluginServer(t) |
|
| 183 | 182 |
|
| 184 | 183 |
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
| 185 | 184 |
var output Manifest |
| ... | ... |
@@ -208,8 +198,7 @@ func TestClientStream(t *testing.T) {
|
| 208 | 208 |
} |
| 209 | 209 |
|
| 210 | 210 |
func TestClientSendFile(t *testing.T) {
|
| 211 |
- addr := setupRemotePluginServer() |
|
| 212 |
- defer teardownRemotePluginServer() |
|
| 211 |
+ mux, addr := setupRemotePluginServer(t) |
|
| 213 | 212 |
|
| 214 | 213 |
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
| 215 | 214 |
var output Manifest |
| ... | ... |
@@ -85,8 +85,7 @@ func TestGet(t *testing.T) {
|
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 | 87 |
func TestPluginWithNoManifest(t *testing.T) {
|
| 88 |
- addr := setupRemotePluginServer() |
|
| 89 |
- defer teardownRemotePluginServer() |
|
| 88 |
+ mux, addr := setupRemotePluginServer(t) |
|
| 90 | 89 |
|
| 91 | 90 |
m := Manifest{[]string{fruitImplements}}
|
| 92 | 91 |
var buf bytes.Buffer |