Skip to content

Commit

Permalink
fix codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
hantmac committed Feb 28, 2024
1 parent d7e1817 commit 24158c7
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/daemon/criruntime/imageruntime/docker_test.go
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")
}
})
}
}

0 comments on commit 24158c7

Please sign in to comment.