Browse code

integration-cli: minor cleanups in stats tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/10/27 17:10:44
Showing 3 changed files
... ...
@@ -174,7 +174,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
174 174
 		c.Fatal("stream was not closed after container was removed")
175 175
 	case sr := <-bc:
176 176
 		dec := json.NewDecoder(sr.stats.Body)
177
-		var s *container.StatsResponse
177
+		var s container.StatsResponse
178 178
 		// decode only one object from the stream
179 179
 		err := dec.Decode(&s)
180 180
 		_ = sr.stats.Body.Close()
... ...
@@ -37,10 +37,10 @@ func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
37 37
 	assert.Equal(c, resp.Header.Get("Content-Type"), "application/json")
38 38
 	assert.Equal(c, resp.Header.Get("Content-Type"), "application/json")
39 39
 
40
-	var v *container.StatsResponse
40
+	var v container.StatsResponse
41 41
 	err = json.NewDecoder(body).Decode(&v)
42 42
 	assert.NilError(c, err)
43
-	body.Close()
43
+	_ = body.Close()
44 44
 
45 45
 	cpuPercent := 0.0
46 46
 
... ...
@@ -76,7 +76,7 @@ func (s *DockerAPISuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T)
76 76
 		info := system.Info{}
77 77
 		err = json.NewDecoder(body).Decode(&info)
78 78
 		assert.NilError(c, err)
79
-		body.Close()
79
+		_ = body.Close()
80 80
 		return info.NGoroutines
81 81
 	}
82 82
 
... ...
@@ -84,7 +84,7 @@ func (s *DockerAPISuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T)
84 84
 	routines := getGoRoutines()
85 85
 	_, body, err := request.Get(testutil.GetContext(c), "/containers/"+id+"/stats")
86 86
 	assert.NilError(c, err)
87
-	body.Close()
87
+	_ = body.Close()
88 88
 
89 89
 	t := time.After(30 * time.Second)
90 90
 	for {
... ...
@@ -167,14 +167,13 @@ func (s *DockerAPISuite) TestAPIStatsNetworkStats(c *testing.T) {
167 167
 }
168 168
 
169 169
 func getNetworkStats(t *testing.T, id string) map[string]container.NetworkStats {
170
-	var st *container.StatsResponse
171
-
172 170
 	_, body, err := request.Get(testutil.GetContext(t), "/containers/"+id+"/stats?stream=false")
173 171
 	assert.NilError(t, err)
174 172
 
173
+	var st container.StatsResponse
175 174
 	err = json.NewDecoder(body).Decode(&st)
176 175
 	assert.NilError(t, err)
177
-	body.Close()
176
+	_ = body.Close()
178 177
 
179 178
 	return st.Networks
180 179
 }
... ...
@@ -194,10 +194,10 @@ func (s *DockerCLIUpdateSuite) TestUpdateStats(c *testing.T) {
194 194
 		assert.NilError(c, err)
195 195
 		assert.Equal(c, resp.Header.Get("Content-Type"), "application/json")
196 196
 
197
-		var v *container.StatsResponse
197
+		var v container.StatsResponse
198 198
 		err = json.NewDecoder(body).Decode(&v)
199 199
 		assert.NilError(c, err)
200
-		body.Close()
200
+		_ = body.Close()
201 201
 
202 202
 		return v.MemoryStats.Limit
203 203
 	}