Browse code

use StatsResponse instead of Stats in tests

The StatsResponse type was a compatibility-wrapper introduced in
d3379946ec96fb6163cb8c4517d7d5a067045801 to differentiate responses
for API < 1.21 and API >= 1.21. API versions lower than 1.24 are
deprecated, and we should merge StatsResponse and Stats, but let's
start with using the StatsResponse in our tests.

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

Sebastiaan van Stijn authored on 2025/01/16 01:44:05
Showing 4 changed files
... ...
@@ -177,7 +177,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
177 177
 	case sr := <-bc:
178 178
 		dec := json.NewDecoder(sr.stats.Body)
179 179
 		defer sr.stats.Body.Close()
180
-		var s *container.Stats
180
+		var s *container.StatsResponse
181 181
 		// decode only one object from the stream
182 182
 		assert.NilError(c, dec.Decode(&s))
183 183
 	}
... ...
@@ -34,7 +34,7 @@ func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
34 34
 	assert.Equal(c, resp.Header.Get("Content-Type"), "application/json")
35 35
 	assert.Equal(c, resp.Header.Get("Content-Type"), "application/json")
36 36
 
37
-	var v *container.Stats
37
+	var v *container.StatsResponse
38 38
 	err = json.NewDecoder(body).Decode(&v)
39 39
 	assert.NilError(c, err)
40 40
 	body.Close()
... ...
@@ -263,7 +263,7 @@ func (s *DockerAPISuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) {
263 263
 		if resp.Header.Get("Content-Type") != "application/json" {
264 264
 			ch <- fmt.Errorf("Invalid 'Content-Type' %v", resp.Header.Get("Content-Type"))
265 265
 		}
266
-		var v *container.Stats
266
+		var v *container.StatsResponse
267 267
 		if err := json.NewDecoder(body).Decode(&v); err != nil {
268 268
 			ch <- err
269 269
 		}
... ...
@@ -186,7 +186,7 @@ func (s *DockerCLIUpdateSuite) TestUpdateStats(c *testing.T) {
186 186
 		assert.NilError(c, err)
187 187
 		assert.Equal(c, resp.Header.Get("Content-Type"), "application/json")
188 188
 
189
-		var v *container.Stats
189
+		var v *container.StatsResponse
190 190
 		err = json.NewDecoder(body).Decode(&v)
191 191
 		assert.NilError(c, err)
192 192
 		body.Close()
... ...
@@ -28,7 +28,7 @@ func TestStats(t *testing.T) {
28 28
 	assert.NilError(t, err)
29 29
 	defer resp.Body.Close()
30 30
 
31
-	var v containertypes.Stats
31
+	var v containertypes.StatsResponse
32 32
 	err = json.NewDecoder(resp.Body).Decode(&v)
33 33
 	assert.NilError(t, err)
34 34
 	assert.Check(t, is.Equal(int64(v.MemoryStats.Limit), info.MemTotal))
... ...
@@ -40,7 +40,7 @@ func TestStats(t *testing.T) {
40 40
 	assert.NilError(t, err)
41 41
 	defer resp.Body.Close()
42 42
 
43
-	v = containertypes.Stats{}
43
+	v = containertypes.StatsResponse{}
44 44
 	err = json.NewDecoder(resp.Body).Decode(&v)
45 45
 	assert.NilError(t, err)
46 46
 	assert.Check(t, is.Equal(int64(v.MemoryStats.Limit), info.MemTotal))