Skip to content

Commit

Permalink
Merge pull request #2131 from MartinForReal/shafan/fixteest
Browse files Browse the repository at this point in the history
Refactor:expose gomock controller in fake object
  • Loading branch information
k8s-ci-robot committed Dec 20, 2023
2 parents 14e6f74 + 9adb6a9 commit 4018fb1
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 171 deletions.
40 changes: 30 additions & 10 deletions pkg/azuredisk/azuredisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func TestNewDriverV1(t *testing.T) {
}

func TestCheckDiskCapacity(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
size := int32(10)
diskName := "unit-test"
resourceGroup := "unit-test"
Expand Down Expand Up @@ -102,14 +104,18 @@ func TestRun(t *testing.T) {

t.Setenv(consts.DefaultAzureCredentialFileEnv, fakeCredFile)

d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
d.Run("tcp://127.0.0.1:0", "", true, true)
},
},
{
name: "Successful run without cloud config",
testFunc: func(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
d.Run("tcp://127.0.0.1:0", "", true, true)
},
},
Expand All @@ -128,7 +134,9 @@ func TestRun(t *testing.T) {

t.Setenv(consts.DefaultAzureCredentialFileEnv, fakeCredFile)

d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
d.setCloud(&azure.Cloud{})
d.setNodeID("")
d.Run("tcp://127.0.0.1:0", "", true, true)
Expand Down Expand Up @@ -169,7 +177,9 @@ func TestRun(t *testing.T) {
}

func TestDriver_checkDiskExists(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
_, err := d.checkDiskExists(context.TODO(), "testurl/subscriptions/12/providers/Microsoft.Compute/disks/name")
assert.NotEqual(t, err, nil)
}
Expand Down Expand Up @@ -269,7 +279,9 @@ func TestWaitForSnapshot(t *testing.T) {
{
name: "snapshotID not valid",
testFunc: func(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
subID := "subs"
resourceGroup := "rg"
intervel := 1 * time.Millisecond
Expand Down Expand Up @@ -302,7 +314,9 @@ func TestWaitForSnapshot(t *testing.T) {
{
name: "timeout for waiting snapshot copy cross region",
testFunc: func(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
subID := "subs"
resourceGroup := "rg"
intervel := 1 * time.Millisecond
Expand Down Expand Up @@ -343,7 +357,9 @@ func TestWaitForSnapshot(t *testing.T) {
{
name: "succeed for waiting snapshot copy cross region",
testFunc: func(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
subID := "subs"
resourceGroup := "rg"
intervel := 1 * time.Millisecond
Expand Down Expand Up @@ -431,7 +447,9 @@ func TestGetVMSSInstanceName(t *testing.T) {
}

func TestGetUsedLunsFromVolumeAttachments(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
tests := []struct {
name string
nodeName string
Expand All @@ -457,7 +475,9 @@ func TestGetUsedLunsFromVolumeAttachments(t *testing.T) {
}

func TestGetUsedLunsFromNode(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
vm := compute.VirtualMachine{}
dataDisks := make([]compute.DataDisk, 2)
dataDisks[0] = compute.DataDisk{Lun: pointer.Int32(int32(0)), Name: &testVolumeName}
Expand Down
8 changes: 6 additions & 2 deletions pkg/azuredisk/azuredisk_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
)

func TestCheckDiskCapacity_V1(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
size := int32(10)
diskName := "unit-test"
resourceGroup := "unit-test"
Expand All @@ -48,7 +50,9 @@ func TestCheckDiskCapacity_V1(t *testing.T) {
}

func TestDriver_checkDiskExists_V1(t *testing.T) {
d, _ := NewFakeDriver(t)
cntl := gomock.NewController(t)
defer cntl.Finish()
d, _ := NewFakeDriver(cntl)
d.setThrottlingCache(consts.GetDiskThrottlingKey, "")
_, err := d.checkDiskExists(context.TODO(), "testurl/subscriptions/12/resourceGroups/23/providers/Microsoft.Compute/disks/name")
assert.Equal(t, err, nil)
Expand Down
Loading

0 comments on commit 4018fb1

Please sign in to comment.