File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed
Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -95,14 +95,21 @@ func (this Hoverfly) Stop() {
9595}
9696
9797func (this Hoverfly ) StopAPIAuthenticated (username , password string ) {
98- token , err := this .getAPIToken (username , password )
99- if err != nil {
100- return
101- }
102- _ , err = doRequest (sling .New ().Delete (this .adminUrl + "/api/v2/shutdown" ).Add ("Authorization" , "Bearer " + token ))
103- if err != nil {
104- panic (err )
105- }
98+ // In teardown, we should be tolerant to failures when shutting down.
99+ // If Hoverfly is already stopped or the connection closes early (EOF), just return.
100+ token , err := this .getAPIToken (username , password )
101+ if err != nil {
102+ return
103+ }
104+ resp , err := doRequest (sling .New ().Delete (this .adminUrl + "/api/v2/shutdown" ).Add ("Authorization" , "Bearer " + token ))
105+ if resp != nil && resp .Body != nil {
106+ io .Copy (io .Discard , resp .Body )
107+ resp .Body .Close ()
108+ }
109+ if err != nil {
110+ // swallow error to avoid panicking AfterEach
111+ return
112+ }
106113}
107114
108115func (this Hoverfly ) DeleteBoltDb () {
You can’t perform that action at this time.
0 commit comments