Browse code

client: reduce uses of obsolete API versions in tests

TestGetAPIPath: don't use obsolete API versions in test

This test was using API v1.22 as "old" version to verify the given
version overrode the default. Update it to use a previous API version
that's still supported by the client.

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

Sebastiaan van Stijn authored on 2025/09/18 00:26:34
Showing 1 changed files
... ...
@@ -78,9 +78,9 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
78 78
 		{
79 79
 			doc: "override api version",
80 80
 			envs: map[string]string{
81
-				"DOCKER_API_VERSION": "1.22",
81
+				"DOCKER_API_VERSION": "1.50",
82 82
 			},
83
-			expectedVersion: "1.22",
83
+			expectedVersion: "1.50",
84 84
 		},
85 85
 	}
86 86
 
... ...
@@ -129,43 +129,43 @@ func TestGetAPIPath(t *testing.T) {
129 129
 			expected: "/v" + MaxAPIVersion + "/containers/json?s=c",
130 130
 		},
131 131
 		{
132
-			version:  "1.22",
132
+			version:  "1.50",
133 133
 			path:     "/containers/json",
134
-			expected: "/v1.22/containers/json",
134
+			expected: "/v1.50/containers/json",
135 135
 		},
136 136
 		{
137
-			version:  "1.22",
137
+			version:  "1.50",
138 138
 			path:     "/containers/json",
139 139
 			query:    url.Values{},
140
-			expected: "/v1.22/containers/json",
140
+			expected: "/v1.50/containers/json",
141 141
 		},
142 142
 		{
143
-			version:  "1.22",
143
+			version:  "1.50",
144 144
 			path:     "/containers/json",
145 145
 			query:    url.Values{"s": []string{"c"}},
146
-			expected: "/v1.22/containers/json?s=c",
146
+			expected: "/v1.50/containers/json?s=c",
147 147
 		},
148 148
 		{
149
-			version:  "v1.22",
149
+			version:  "v1.50",
150 150
 			path:     "/containers/json",
151
-			expected: "/v1.22/containers/json",
151
+			expected: "/v1.50/containers/json",
152 152
 		},
153 153
 		{
154
-			version:  "v1.22",
154
+			version:  "v1.50",
155 155
 			path:     "/containers/json",
156 156
 			query:    url.Values{},
157
-			expected: "/v1.22/containers/json",
157
+			expected: "/v1.50/containers/json",
158 158
 		},
159 159
 		{
160
-			version:  "v1.22",
160
+			version:  "v1.50",
161 161
 			path:     "/containers/json",
162 162
 			query:    url.Values{"s": []string{"c"}},
163
-			expected: "/v1.22/containers/json?s=c",
163
+			expected: "/v1.50/containers/json?s=c",
164 164
 		},
165 165
 		{
166
-			version:  "v1.22",
166
+			version:  "v1.50",
167 167
 			path:     "/networks/kiwl$%^",
168
-			expected: "/v1.22/networks/kiwl$%25%5E",
168
+			expected: "/v1.50/networks/kiwl$%25%5E",
169 169
 		},
170 170
 	}
171 171
 
... ...
@@ -236,7 +236,7 @@ func TestNewClientWithOpsFromEnvSetsDefaultVersion(t *testing.T) {
236 236
 	assert.NilError(t, err)
237 237
 	assert.Check(t, is.Equal(client.ClientVersion(), MaxAPIVersion))
238 238
 
239
-	const expected = "1.22"
239
+	const expected = "1.50"
240 240
 	t.Setenv("DOCKER_API_VERSION", expected)
241 241
 	client, err = NewClientWithOpts(FromEnv)
242 242
 	assert.NilError(t, err)
... ...
@@ -398,7 +398,7 @@ func TestNegotiateAPIVersionWithEmptyVersion(t *testing.T) {
398 398
 	client, err := NewClientWithOpts(WithVersion(""))
399 399
 	assert.NilError(t, err)
400 400
 
401
-	const expected = "1.35"
401
+	const expected = "1.50"
402 402
 	client.NegotiateAPIVersionPing(types.Ping{APIVersion: expected})
403 403
 	assert.Check(t, is.Equal(client.ClientVersion(), expected))
404 404
 }
... ...
@@ -406,11 +406,11 @@ func TestNegotiateAPIVersionWithEmptyVersion(t *testing.T) {
406 406
 // TestNegotiateAPIVersionWithFixedVersion asserts that initializing a client
407 407
 // with a fixed version disables API-version negotiation
408 408
 func TestNegotiateAPIVersionWithFixedVersion(t *testing.T) {
409
-	const customVersion = "1.35"
409
+	const customVersion = "1.50"
410 410
 	client, err := NewClientWithOpts(WithVersion(customVersion))
411 411
 	assert.NilError(t, err)
412 412
 
413
-	client.NegotiateAPIVersionPing(types.Ping{APIVersion: "1.31"})
413
+	client.NegotiateAPIVersionPing(types.Ping{APIVersion: "1.49"})
414 414
 	assert.Check(t, is.Equal(client.ClientVersion(), customVersion))
415 415
 }
416 416
 
... ...
@@ -418,42 +418,65 @@ func TestNegotiateAPIVersionWithFixedVersion(t *testing.T) {
418 418
 // version.
419 419
 func TestCustomAPIVersion(t *testing.T) {
420 420
 	tests := []struct {
421
+		doc      string
421 422
 		version  string
422 423
 		expected string
423 424
 	}{
424 425
 		{
426
+			doc:      "empty version",
425 427
 			version:  "",
426 428
 			expected: MaxAPIVersion,
427 429
 		},
428 430
 		{
429
-			version:  "1.0",
430
-			expected: "1.0",
431
+			doc:      "custom lower version, no v-prefix",
432
+			version:  "1.50",
433
+			expected: "1.50",
431 434
 		},
432 435
 		{
436
+			// We allow upgrading the client to an unsupported higher version for testing.
437
+			doc:      "upgrade version, no v-prefix",
433 438
 			version:  "9.99",
434 439
 			expected: "9.99",
435 440
 		},
436 441
 		{
442
+			// We currently ignore malformed versions.
443
+			doc:      "empty version, with v-prefix",
437 444
 			version:  "v",
438 445
 			expected: MaxAPIVersion,
439 446
 		},
440 447
 		{
441
-			version:  "v1.0",
442
-			expected: "1.0",
448
+			doc:      "custom lower version, with v-prefix",
449
+			version:  "v1.50",
450
+			expected: "1.50",
443 451
 		},
444 452
 		{
453
+			// We allow upgrading the client to an unsupported higher version for testing.
454
+			doc:      "upgrade version, with v-prefix",
445 455
 			version:  "v9.99",
446 456
 			expected: "9.99",
447 457
 		},
448 458
 		{
459
+			// We currently allow downgrading the client to an unsupported lower version for testing.
460
+			doc:      "downgrade unsupported version, no v-prefix",
461
+			version:  "1.0",
462
+			expected: "1.0",
463
+		},
464
+		{
465
+			// We currently allow downgrading the client to an unsupported lower version for testing.
466
+			doc:      "downgrade unsupported version, no v-prefix",
467
+			version:  "v1.0",
468
+			expected: "1.0",
469
+		},
470
+		{
449 471
 			// When manually setting a version, no validation happens.
450 472
 			// so anything is accepted.
473
+			doc:      "malformed version",
451 474
 			version:  "something-weird",
452 475
 			expected: "something-weird",
453 476
 		},
454 477
 	}
455 478
 	for _, tc := range tests {
456
-		t.Run(tc.version, func(t *testing.T) {
479
+		t.Run(tc.doc, func(t *testing.T) {
457 480
 			client, err := NewClientWithOpts(WithVersion(tc.version))
458 481
 			assert.NilError(t, err)
459 482
 			assert.Check(t, is.Equal(client.ClientVersion(), tc.expected))