Skip to content

Commit

Permalink
test: Increased unit tests coverage for criapi.go
Browse files Browse the repository at this point in the history
  • Loading branch information
samihan-dell committed Feb 12, 2025
1 parent e9c1238 commit 25563dd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/criapi/criapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"reflect"
"testing"
"time"

"google.golang.org/grpc"
v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
Expand Down Expand Up @@ -49,6 +50,41 @@ func TestNewCRIClient(t *testing.T) {
}
}

func TestNewCRIClient_withMocking(t *testing.T) {
copyGetGrpcDialContext := getGrpcDialContext

Check failure on line 54 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext

Check failure on line 54 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext

Check failure on line 54 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext

Check failure on line 54 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext
copyCRIClientDialRetry := CRIClientDialRetry
getGrpcDialContext = func(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {

Check failure on line 56 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext

Check failure on line 56 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext

Check failure on line 56 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext
return nil, nil
}
CRIClientDialRetry = 1 * time.Second

defer func() {
getGrpcDialContext = copyGetGrpcDialContext

Check failure on line 62 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext (typecheck)

Check failure on line 62 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext (typecheck)

Check failure on line 62 in internal/criapi/criapi_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

undefined: getGrpcDialContext (typecheck)
CRIClientDialRetry = copyCRIClientDialRetry
}()

tests := []struct {
name string
criSock string
wantErr bool
}{
{
name: "Valid connection",
criSock: "unix:///var/run/dockershim.sock",
wantErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := NewCRIClient(tt.criSock)
if (err != nil) != tt.wantErr {
t.Errorf("NewCRIClient() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func TestClient_Connected(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 25563dd

Please sign in to comment.