Fix #23012
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
| ... | ... |
@@ -28,7 +28,7 @@ const pluginAddress = "authzplugin.sock" |
| 28 | 28 |
|
| 29 | 29 |
func TestAuthZRequestPluginError(t *testing.T) {
|
| 30 | 30 |
server := authZPluginTestServer{t: t}
|
| 31 |
- go server.start() |
|
| 31 |
+ server.start() |
|
| 32 | 32 |
defer server.stop() |
| 33 | 33 |
|
| 34 | 34 |
authZPlugin := createTestPlugin(t) |
| ... | ... |
@@ -59,7 +59,7 @@ func TestAuthZRequestPluginError(t *testing.T) {
|
| 59 | 59 |
|
| 60 | 60 |
func TestAuthZRequestPlugin(t *testing.T) {
|
| 61 | 61 |
server := authZPluginTestServer{t: t}
|
| 62 |
- go server.start() |
|
| 62 |
+ server.start() |
|
| 63 | 63 |
defer server.stop() |
| 64 | 64 |
|
| 65 | 65 |
authZPlugin := createTestPlugin(t) |
| ... | ... |
@@ -91,7 +91,7 @@ func TestAuthZRequestPlugin(t *testing.T) {
|
| 91 | 91 |
|
| 92 | 92 |
func TestAuthZResponsePlugin(t *testing.T) {
|
| 93 | 93 |
server := authZPluginTestServer{t: t}
|
| 94 |
- go server.start() |
|
| 94 |
+ server.start() |
|
| 95 | 95 |
defer server.stop() |
| 96 | 96 |
|
| 97 | 97 |
authZPlugin := createTestPlugin(t) |
| ... | ... |
@@ -223,6 +223,7 @@ type authZPluginTestServer struct {
|
| 223 | 223 |
recordedRequest Request |
| 224 | 224 |
// response stores the response sent from the plugin to the daemon |
| 225 | 225 |
replayResponse Response |
| 226 |
+ server *httptest.Server |
|
| 226 | 227 |
} |
| 227 | 228 |
|
| 228 | 229 |
// start starts the test server that implements the plugin |
| ... | ... |
@@ -234,12 +235,19 @@ func (t *authZPluginTestServer) start() {
|
| 234 | 234 |
r.HandleFunc("/Plugin.Activate", t.activate)
|
| 235 | 235 |
r.HandleFunc("/"+AuthZApiRequest, t.auth)
|
| 236 | 236 |
r.HandleFunc("/"+AuthZApiResponse, t.auth)
|
| 237 |
- server := http.Server{Handler: r, Addr: pluginAddress}
|
|
| 238 |
- server.Serve(l) |
|
| 237 |
+ t.server = &httptest.Server{
|
|
| 238 |
+ Listener: l, |
|
| 239 |
+ Config: &http.Server{
|
|
| 240 |
+ Handler: r, |
|
| 241 |
+ Addr: pluginAddress, |
|
| 242 |
+ }, |
|
| 243 |
+ } |
|
| 244 |
+ t.server.Start() |
|
| 239 | 245 |
} |
| 240 | 246 |
|
| 241 | 247 |
// stop stops the test server that implements the plugin |
| 242 | 248 |
func (t *authZPluginTestServer) stop() {
|
| 249 |
+ t.server.Close() |
|
| 243 | 250 |
os.Remove(pluginAddress) |
| 244 | 251 |
if t.listener != nil {
|
| 245 | 252 |
t.listener.Close() |