forked from openkruise/kruise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: upgrade minimum dockerapi version (openkruise#1510)
* fix: upgrade minimum dockerapi version Signed-off-by: hantmac <hantmac@outlook.com> * fix codecov Signed-off-by: hantmac <hantmac@outlook.com> --------- Signed-off-by: hantmac <hantmac@outlook.com>
- Loading branch information
Showing
2 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package imageruntime | ||
|
||
import ( | ||
"testing" | ||
|
||
dockerapi "github.com/docker/docker/client" | ||
) | ||
|
||
func TestCreateRuntimeClientIfNecessary(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
clientExists bool | ||
expectedError error | ||
}{ | ||
{ | ||
name: "ClientAlreadyExists", | ||
clientExists: true, | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "ClientDoesNotExist", | ||
clientExists: false, | ||
expectedError: nil, // Assuming that dockerapi.NewClientWithOpts does not return an error in this test environment | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
d := &dockerImageService{ | ||
runtimeURI: "unix:///hostvarrun/docker.sock", | ||
} | ||
if tt.clientExists { | ||
d.client = &dockerapi.Client{} | ||
} | ||
|
||
err := d.createRuntimeClientIfNecessary() | ||
|
||
if err != tt.expectedError { | ||
t.Errorf("createRuntimeClientIfNecessary() error = %v, expectedError %v", err, tt.expectedError) | ||
} | ||
|
||
if !tt.clientExists && d.client == nil { | ||
t.Errorf("createRuntimeClientIfNecessary() client was not created") | ||
} | ||
}) | ||
} | ||
} |