@@ -42,18 +42,17 @@ func TestServer(t *testing.T) {
4242 testErrCh <- err
4343 return
4444 }
45+ defer resp .Body .Close ()
4546
46- if resp .Body != nil {
47- all , err := io .ReadAll (resp .Body )
48- if err != nil {
49- testErrCh <- err
50- return
51- }
52- all = bytes .TrimSpace (all )
53- if string (all ) != `{"Code":0,"Msg":""}` {
54- testErrCh <- fmt .Errorf ("unexpected response: %s" , string (all ))
55- return
56- }
47+ all , err := io .ReadAll (resp .Body )
48+ if err != nil {
49+ testErrCh <- err
50+ return
51+ }
52+ all = bytes .TrimSpace (all )
53+ if string (all ) != `{"Code":0,"Msg":""}` {
54+ testErrCh <- fmt .Errorf ("unexpected response: %s" , string (all ))
55+ return
5756 }
5857 testErrCh <- nil
5958 }()
@@ -101,18 +100,17 @@ func TestServerCmdActions(t *testing.T) {
101100 testErrCh <- err
102101 return
103102 }
103+ defer resp .Body .Close ()
104104
105- if resp .Body != nil {
106- all , err := io .ReadAll (resp .Body )
107- if err != nil {
108- testErrCh <- err
109- return
110- }
111- all = bytes .TrimSpace (all )
112- if ! bytes .HasPrefix (all , []byte (`{"Code":0` )) {
113- testErrCh <- fmt .Errorf ("unexpected response: %s, %x" , string (all ), all )
114- return
115- }
105+ all , err := io .ReadAll (resp .Body )
106+ if err != nil {
107+ testErrCh <- err
108+ return
109+ }
110+ all = bytes .TrimSpace (all )
111+ if ! bytes .HasPrefix (all , []byte (`{"Code":0` )) {
112+ testErrCh <- fmt .Errorf ("unexpected response: %s, %x" , string (all ), all )
113+ return
116114 }
117115 testErrCh <- nil
118116 }()
@@ -183,18 +181,17 @@ func TestServerForward(t *testing.T) {
183181 testErrCh <- err
184182 return
185183 }
184+ defer resp .Body .Close ()
186185
187- if resp .Body != nil {
188- all , err := io .ReadAll (resp .Body )
189- if err != nil {
190- testErrCh <- err
191- return
192- }
193- all = bytes .TrimSpace (all )
194- if string (all ) != `{"Code":0,"Msg":""}` {
195- testErrCh <- fmt .Errorf ("unexpected response: %s" , string (all ))
196- return
197- }
186+ all , err := io .ReadAll (resp .Body )
187+ if err != nil {
188+ testErrCh <- err
189+ return
190+ }
191+ all = bytes .TrimSpace (all )
192+ if string (all ) != `{"Code":0,"Msg":""}` {
193+ testErrCh <- fmt .Errorf ("unexpected response: %s" , string (all ))
194+ return
198195 }
199196 testErrCh <- nil
200197 }()
@@ -247,18 +244,17 @@ func TestAttendanceAPI(t *testing.T) {
247244 testErrCh <- err
248245 return
249246 }
247+ defer resp .Body .Close ()
250248
251- if resp .Body != nil {
252- all , err := io .ReadAll (resp .Body )
253- if err != nil {
254- testErrCh <- err
255- return
256- }
257- all = bytes .TrimSpace (all )
258- if string (all ) != `{"Code":0,"Msg":""}` {
259- testErrCh <- fmt .Errorf ("unexpected response: %s" , string (all ))
260- return
261- }
249+ all , err := io .ReadAll (resp .Body )
250+ if err != nil {
251+ testErrCh <- err
252+ return
253+ }
254+ all = bytes .TrimSpace (all )
255+ if string (all ) != `{"Code":0,"Msg":""}` {
256+ testErrCh <- fmt .Errorf ("unexpected response: %s" , string (all ))
257+ return
262258 }
263259 testErrCh <- nil
264260 }()
0 commit comments