-
Notifications
You must be signed in to change notification settings - Fork 93
Refactor: adopt dependency injection pattern and extract cloud property #1094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,18 +163,6 @@ func TestCreateVolume(t *testing.T) { | |
name string | ||
testFunc func(t *testing.T) | ||
}{ | ||
{ | ||
name: "invalid create volume req", | ||
testFunc: func(t *testing.T) { | ||
d := NewFakeDriver() | ||
req := &csi.CreateVolumeRequest{} | ||
_, err := d.CreateVolume(context.Background(), req) | ||
expectedErr := status.Error(codes.InvalidArgument, "CREATE_DELETE_VOLUME") | ||
if !reflect.DeepEqual(err, expectedErr) { | ||
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "volume Name missing", | ||
testFunc: func(t *testing.T) { | ||
|
@@ -893,20 +881,6 @@ func TestDeleteVolume(t *testing.T) { | |
} | ||
}, | ||
}, | ||
{ | ||
name: "invalid delete volume req", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you also add this ut back? |
||
testFunc: func(t *testing.T) { | ||
d := NewFakeDriver() | ||
req := &csi.DeleteVolumeRequest{ | ||
VolumeId: "unit-test", | ||
} | ||
_, err := d.DeleteVolume(context.Background(), req) | ||
expectedErr := status.Errorf(codes.Internal, "invalid delete volume req: volume_id:\"unit-test\" ") | ||
if !reflect.DeepEqual(err, expectedErr) { | ||
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "invalid volume Id", | ||
testFunc: func(t *testing.T) { | ||
|
@@ -1298,21 +1272,6 @@ func TestControllerExpandVolume(t *testing.T) { | |
} | ||
}, | ||
}, | ||
{ | ||
name: "invalid expand volume req", | ||
testFunc: func(t *testing.T) { | ||
d := NewFakeDriver() | ||
req := &csi.ControllerExpandVolumeRequest{ | ||
VolumeId: "unit-test", | ||
CapacityRange: &csi.CapacityRange{}, | ||
} | ||
_, err := d.ControllerExpandVolume(context.Background(), req) | ||
expectedErr := status.Errorf(codes.Internal, "invalid expand volume req: volume_id:\"unit-test\" capacity_range:<> ") | ||
if !reflect.DeepEqual(err, expectedErr) { | ||
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "Volume Size exceeds Max Container Size", | ||
testFunc: func(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,31 +81,34 @@ func handle() { | |
driverOptions := blob.DriverOptions{ | ||
NodeID: *nodeID, | ||
DriverName: *driverName, | ||
CloudConfigSecretName: *cloudConfigSecretName, | ||
CloudConfigSecretNamespace: *cloudConfigSecretNamespace, | ||
BlobfuseProxyEndpoint: *blobfuseProxyEndpoint, | ||
EnableBlobfuseProxy: *enableBlobfuseProxy, | ||
BlobfuseProxyConnTimout: *blobfuseProxyConnTimout, | ||
EnableBlobMockMount: *enableBlobMockMount, | ||
CustomUserAgent: *customUserAgent, | ||
UserAgentSuffix: *userAgentSuffix, | ||
AllowEmptyCloudConfig: *allowEmptyCloudConfig, | ||
EnableGetVolumeStats: *enableGetVolumeStats, | ||
AppendTimeStampInCacheDir: *appendTimeStampInCacheDir, | ||
MountPermissions: *mountPermissions, | ||
AllowInlineVolumeKeyAccessWithIdentity: *allowInlineVolumeKeyAccessWithIdentity, | ||
AppendMountErrorHelpLink: *appendMountErrorHelpLink, | ||
KubeAPIQPS: *kubeAPIQPS, | ||
KubeAPIBurst: *kubeAPIBurst, | ||
EnableAznfsMount: *enableAznfsMount, | ||
VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes, | ||
SasTokenExpirationMinutes: *sasTokenExpirationMinutes, | ||
} | ||
driver := blob.NewDriver(&driverOptions) | ||
|
||
userAgent := blob.GetUserAgent(driverOptions.DriverName, *customUserAgent, *userAgentSuffix) | ||
klog.V(2).Infof("driver userAgent: %s", userAgent) | ||
|
||
cloud, err := blob.GetCloudProvider(*kubeconfig, driverOptions.NodeID, *cloudConfigSecretName, *cloudConfigSecretNamespace, userAgent, *allowEmptyCloudConfig, *kubeAPIQPS, *kubeAPIBurst) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not put all these into
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a little bit complicated to add mock for GetCloudProvider There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but why move part of the options as parameters? this is not consistent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I move other dependencies out of newDriver function? In that case that would be easier to compose driver object and there is no need to implement FakeDriver. |
||
if err != nil { | ||
klog.Fatalf("failed to get Azure Cloud Provider, error: %v", err) | ||
} | ||
klog.V(2).Infof("cloud: %s, location: %s, rg: %s, VnetName: %s, VnetResourceGroup: %s, SubnetName: %s", cloud.Cloud, cloud.Location, cloud.ResourceGroup, cloud.VnetName, cloud.VnetResourceGroup, cloud.SubnetName) | ||
|
||
driver := blob.NewDriver(&driverOptions, cloud) | ||
if driver == nil { | ||
klog.Fatalln("Failed to initialize Azure Blob Storage CSI driver") | ||
} | ||
driver.Run(*endpoint, *kubeconfig, false) | ||
driver.Run(*endpoint, false) | ||
} | ||
|
||
func exportMetrics() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is deleted because fake driver has got required capabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the result of this test now?
invalid create volume req"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
original test is for testing
invalid create volume req
, not capabilities