mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Enrich the unit tests for azure_storage
This commit is contained in:
parent
440b5c2fbc
commit
f88ac4e70f
@ -19,6 +19,7 @@ limitations under the License.
|
|||||||
package azure
|
package azure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
|
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
|
||||||
@ -32,11 +33,7 @@ func TestCreateFileShare(t *testing.T) {
|
|||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
||||||
cloud := &Cloud{}
|
cloud := &Cloud{controllerCommon: &controllerCommon{resourceGroup: "rg"}}
|
||||||
mockFileClient := mockfileclient.NewMockInterface(ctrl)
|
|
||||||
mockFileClient.EXPECT().CreateFileShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
|
||||||
cloud.FileClient = mockFileClient
|
|
||||||
|
|
||||||
name := "baz"
|
name := "baz"
|
||||||
sku := "sku"
|
sku := "sku"
|
||||||
kind := "StorageV2"
|
kind := "StorageV2"
|
||||||
@ -45,6 +42,7 @@ func TestCreateFileShare(t *testing.T) {
|
|||||||
bogus := "bogus"
|
bogus := "bogus"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
rg string
|
||||||
name string
|
name string
|
||||||
acct string
|
acct string
|
||||||
acctType string
|
acctType string
|
||||||
@ -95,6 +93,25 @@ func TestCreateFileShare(t *testing.T) {
|
|||||||
expectAcct: "baz",
|
expectAcct: "baz",
|
||||||
expectKey: "key",
|
expectKey: "key",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
rg: "rg",
|
||||||
|
name: "foo",
|
||||||
|
acct: "",
|
||||||
|
acctType: sku,
|
||||||
|
acctKind: kind,
|
||||||
|
loc: location,
|
||||||
|
gb: 10,
|
||||||
|
accounts: []storage.Account{
|
||||||
|
{Name: &name, Sku: &storage.Sku{Name: storage.SkuName(sku)}, Kind: storage.Kind(kind), Location: &location},
|
||||||
|
},
|
||||||
|
keys: storage.AccountListKeysResult{
|
||||||
|
Keys: &[]storage.AccountKey{
|
||||||
|
{Value: &value},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: fmt.Errorf("create fileshare error"),
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "foo",
|
name: "foo",
|
||||||
acct: "",
|
acct: "",
|
||||||
@ -122,13 +139,17 @@ func TestCreateFileShare(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
mockFileClient := mockfileclient.NewMockInterface(ctrl)
|
||||||
|
cloud.FileClient = mockFileClient
|
||||||
|
mockFileClient.EXPECT().CreateFileShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(test.err).AnyTimes()
|
||||||
|
|
||||||
mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
|
mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
|
||||||
cloud.StorageAccountClient = mockStorageAccountsClient
|
cloud.StorageAccountClient = mockStorageAccountsClient
|
||||||
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), "rg", gomock.Any()).Return(test.keys, nil).AnyTimes()
|
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), "rg", gomock.Any()).Return(test.keys, nil).AnyTimes()
|
||||||
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), "rg").Return(test.accounts, nil).AnyTimes()
|
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), "rg").Return(test.accounts, nil).AnyTimes()
|
||||||
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), "rg", gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), "rg", gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
||||||
|
|
||||||
account, key, err := cloud.CreateFileShare(test.name, test.acct, test.acctType, test.acctKind, "rg", test.loc, test.gb)
|
account, key, err := cloud.CreateFileShare(test.name, test.acct, test.acctType, test.acctKind, test.rg, test.loc, test.gb)
|
||||||
if test.expectErr && err == nil {
|
if test.expectErr && err == nil {
|
||||||
t.Errorf("unexpected non-error")
|
t.Errorf("unexpected non-error")
|
||||||
continue
|
continue
|
||||||
@ -151,15 +172,12 @@ func TestDeleteFileShare(t *testing.T) {
|
|||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
||||||
cloud := &Cloud{}
|
cloud := &Cloud{}
|
||||||
mockFileClient := mockfileclient.NewMockInterface(ctrl)
|
|
||||||
mockFileClient.EXPECT().DeleteFileShare(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
|
||||||
cloud.FileClient = mockFileClient
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
rg string
|
rg string
|
||||||
acct string
|
acct string
|
||||||
name string
|
name string
|
||||||
|
|
||||||
|
err error
|
||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -169,11 +187,20 @@ func TestDeleteFileShare(t *testing.T) {
|
|||||||
|
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
rg: "rg",
|
||||||
|
acct: "bar",
|
||||||
|
name: "",
|
||||||
|
|
||||||
|
err: fmt.Errorf("delete fileshare error"),
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
|
mockFileClient := mockfileclient.NewMockInterface(ctrl)
|
||||||
cloud.StorageAccountClient = mockStorageAccountsClient
|
cloud.FileClient = mockFileClient
|
||||||
|
mockFileClient.EXPECT().DeleteFileShare(gomock.Any(), gomock.Any(), gomock.Any()).Return(test.err).Times(1)
|
||||||
|
|
||||||
err := cloud.DeleteFileShare(test.rg, test.acct, test.name)
|
err := cloud.DeleteFileShare(test.rg, test.acct, test.name)
|
||||||
if test.expectErr && err == nil {
|
if test.expectErr && err == nil {
|
||||||
@ -229,3 +256,44 @@ func TestResizeFileShare(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFileShare(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
cloud := &Cloud{}
|
||||||
|
mockFileClient := mockfileclient.NewMockInterface(ctrl)
|
||||||
|
mockFileClient.EXPECT().GetFileShare(gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{}, nil).AnyTimes()
|
||||||
|
cloud.FileClient = mockFileClient
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
rg string
|
||||||
|
acct string
|
||||||
|
name string
|
||||||
|
|
||||||
|
expectErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
rg: "rg",
|
||||||
|
acct: "bar",
|
||||||
|
name: "foo",
|
||||||
|
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
|
||||||
|
cloud.StorageAccountClient = mockStorageAccountsClient
|
||||||
|
|
||||||
|
_, err := cloud.GetFileShare(test.rg, test.acct, test.name)
|
||||||
|
if test.expectErr && err == nil {
|
||||||
|
t.Errorf("unexpected non-error")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !test.expectErr && err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user