@@ -498,7 +498,7 @@ func TestCreateMobyContainer(t *testing.T) {
498498 assert .NilError (t , err )
499499}
500500
501- func TestCurrentAPIVersionCachesNegotiation (t * testing.T ) {
501+ func TestRuntimeAPIVersionCachesNegotiation (t * testing.T ) {
502502 mockCtrl := gomock .NewController (t )
503503 defer mockCtrl .Finish ()
504504
@@ -508,52 +508,25 @@ func TestCurrentAPIVersionCachesNegotiation(t *testing.T) {
508508
509509 cli .EXPECT ().Client ().Return (apiClient ).AnyTimes ()
510510
511+ // Ping reports the server's max API version (1.44), but after negotiation
512+ // the client may settle on a lower version (1.43) — e.g. when the client
513+ // SDK caps at an older version. RuntimeAPIVersion must return the negotiated
514+ // ClientVersion, not the server's raw APIVersion.
511515 apiClient .EXPECT ().Ping (gomock .Any (), client.PingOptions {NegotiateAPIVersion : true }).Return (client.PingResult {
512516 APIVersion : "1.44" ,
513517 }, nil ).Times (1 )
514518 apiClient .EXPECT ().ClientVersion ().Return ("1.43" ).Times (1 )
515519
516- version , err := tested .CurrentAPIVersion (t .Context ())
520+ version , err := tested .RuntimeAPIVersion (t .Context ())
517521 assert .NilError (t , err )
518522 assert .Equal (t , version , "1.43" )
519523
520- version , err = tested .CurrentAPIVersion (t .Context ())
524+ version , err = tested .RuntimeAPIVersion (t .Context ())
521525 assert .NilError (t , err )
522526 assert .Equal (t , version , "1.43" )
523527}
524528
525- func TestRuntimeVersionRetriesOnTransientError (t * testing.T ) {
526- mockCtrl := gomock .NewController (t )
527- defer mockCtrl .Finish ()
528-
529- apiClient := mocks .NewMockAPIClient (mockCtrl )
530- cli := mocks .NewMockCli (mockCtrl )
531- tested := & composeService {dockerCli : cli }
532-
533- cli .EXPECT ().Client ().Return (apiClient ).AnyTimes ()
534-
535- // First call: ServerVersion fails with a transient error
536- firstCall := apiClient .EXPECT ().ServerVersion (gomock .Any (), gomock .Any ()).
537- Return (client.ServerVersionResult {}, context .DeadlineExceeded ).Times (1 )
538-
539- // Second call: succeeds
540- apiClient .EXPECT ().ServerVersion (gomock .Any (), gomock .Any ()).
541- Return (client.ServerVersionResult {APIVersion : "1.48" }, nil ).Times (1 ).After (firstCall )
542-
543- _ , err := tested .RuntimeVersion (t .Context ())
544- assert .ErrorIs (t , err , context .DeadlineExceeded )
545-
546- version , err := tested .RuntimeVersion (t .Context ())
547- assert .NilError (t , err )
548- assert .Equal (t , version , "1.48" )
549-
550- // Third call returns cached value
551- version , err = tested .RuntimeVersion (t .Context ())
552- assert .NilError (t , err )
553- assert .Equal (t , version , "1.48" )
554- }
555-
556- func TestCurrentAPIVersionRetriesOnTransientError (t * testing.T ) {
529+ func TestRuntimeAPIVersionRetriesOnTransientError (t * testing.T ) {
557530 mockCtrl := gomock .NewController (t )
558531 defer mockCtrl .Finish ()
559532
@@ -573,16 +546,16 @@ func TestCurrentAPIVersionRetriesOnTransientError(t *testing.T) {
573546 apiClient .EXPECT ().ClientVersion ().Return ("1.44" ).Times (1 )
574547
575548 // First call should return the transient error
576- _ , err := tested .CurrentAPIVersion (t .Context ())
549+ _ , err := tested .RuntimeAPIVersion (t .Context ())
577550 assert .ErrorIs (t , err , context .DeadlineExceeded )
578551
579552 // Second call should succeed — error was not cached
580- version , err := tested .CurrentAPIVersion (t .Context ())
553+ version , err := tested .RuntimeAPIVersion (t .Context ())
581554 assert .NilError (t , err )
582555 assert .Equal (t , version , "1.44" )
583556
584557 // Third call should return the cached value without calling Ping again
585- version , err = tested .CurrentAPIVersion (t .Context ())
558+ version , err = tested .RuntimeAPIVersion (t .Context ())
586559 assert .NilError (t , err )
587560 assert .Equal (t , version , "1.44" )
588561}
0 commit comments