本文整理匯總了Golang中github.com/cloud-ca/go-cloudca/mocks/services_mocks.NewMockEntityService函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMockEntityService函數的具體用法?Golang NewMockEntityService怎麽用?Golang NewMockEntityService使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewMockEntityService函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestListPublicIpReturnTiersIfSuccess
func TestListPublicIpReturnTiersIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
publicIpService := PublicIpApi{
entityService: mockEntityService,
}
expectedPublicIp1 := PublicIp{Id: "list_id_1",
IpAddress: "list_ip_address_1"}
expectedPublicIp2 := PublicIp{Id: "list_id_2",
IpAddress: "list_ip_address_2"}
expectedPublicIps := []PublicIp{expectedPublicIp1, expectedPublicIp2}
mockEntityService.EXPECT().List(gomock.Any()).Return(buildListTestPublicIpJsonResponse(expectedPublicIps), nil)
//when
publicIps, _ := publicIpService.List()
//then
if assert.NotNil(t, publicIps) {
assert.Equal(t, expectedPublicIps, publicIps)
}
}
示例2: TestListSSHKeyReturnSSHKeysIfSuccess
func TestListSSHKeyReturnSSHKeysIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
sshKeyService := SSHKeyApi{
entityService: mockEntityService,
}
expectedSSHKeys := []SSHKey{
SSHKey{
Name: "list_name_1",
Fingerprint: "list_fingerprint_1",
},
SSHKey{
Name: "list_name_2",
Fingerprint: "list_fingerprint_2",
},
}
mockEntityService.EXPECT().List(gomock.Any()).Return(buildListSSHKeyJsonResponse(expectedSSHKeys), nil)
//when
sshKeys, _ := sshKeyService.List()
//then
if assert.NotNil(t, sshKeys) {
assert.Equal(t, expectedSSHKeys, sshKeys)
}
}
示例3: TestGetPublicIpReturnPublicIpIfSuccess
func TestGetPublicIpReturnPublicIpIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
publicIpService := PublicIpApi{
entityService: mockEntityService,
}
expectedPublicIp := PublicIp{Id: TEST_PUBLIC_IP_ID,
IpAddress: TEST_IP_ADDRESS,
}
mockEntityService.EXPECT().Get(TEST_PUBLIC_IP_ID, gomock.Any()).Return(buildTestPublicIpJsonResponse(&expectedPublicIp), nil)
//when
publicIp, _ := publicIpService.Get(TEST_PUBLIC_IP_ID)
//then
if assert.NotNil(t, publicIp) {
assert.Equal(t, expectedPublicIp, *publicIp)
}
}
示例4: TestChangeComputeOfferingReturnFalseIfError
func TestChangeComputeOfferingReturnFalseIfError(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
instanceService := InstanceApi{
entityService: mockEntityService,
}
mockError := mocks.MockError{"some_change_compute_offering_error"}
mockEntityService.EXPECT().Execute(TEST_INSTANCE_ID, INSTANCE_CHANGE_COMPUTE_OFFERING_OPERATION, gomock.Any(), gomock.Any()).Return([]byte(`{}`), mockError)
instanceWithNewComputeOffering := Instance{
Id: TEST_INSTANCE_ID,
ComputeOfferingId: "new_compute_offering",
}
//when
success, err := instanceService.ChangeComputeOffering(instanceWithNewComputeOffering)
//then
assert.False(t, success)
assert.Equal(t, mockError, err)
}
示例5: TestGetComputeOfferingReturnComputeOfferingIfSuccess
func TestGetComputeOfferingReturnComputeOfferingIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
computeOfferingService := ComputeOfferingApi{
entityService: mockEntityService,
}
expectedComputeOffering := ComputeOffering{Id: TEST_COMPUTE_OFFERING_ID,
Name: TEST_COMPUTE_OFFERING_NAME,
MemoryInMB: TEST_COMPUTE_OFFERING_MEMORY,
CpuCount: TEST_COMPUTE_OFFERING_CPU_NUMBER,
Custom: TEST_COMPUTE_OFFERING_CUSTOM}
mockEntityService.EXPECT().Get(TEST_COMPUTE_OFFERING_ID, gomock.Any()).Return(buildComputeOfferingJsonResponse(&expectedComputeOffering), nil)
//when
computeOffering, _ := computeOfferingService.Get(TEST_COMPUTE_OFFERING_ID)
//then
if assert.NotNil(t, computeOffering) {
assert.Equal(t, expectedComputeOffering, *computeOffering)
}
}
示例6: TestCreateNetworkAclReturnCreatedNetworkAclIfSuccess
func TestCreateNetworkAclReturnCreatedNetworkAclIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
networkAclService := NetworkAclApi{
entityService: mockEntityService,
}
networkAclToCreate := NetworkAcl{Name: "new_name",
Description: "new_description",
VpcId: "new_vpc",
}
mockEntityService.EXPECT().Create(gomock.Any(), gomock.Any()).Return([]byte(`{"id":"new_id"}`), nil)
//when
createdNetworkAcl, _ := networkAclService.Create(networkAclToCreate)
//then
if assert.NotNil(t, createdNetworkAcl) {
assert.Equal(t, "new_id", createdNetworkAcl.Id)
}
}
示例7: TestCreateNetworkAclReturnNilWithErrorIfError
func TestCreateNetworkAclReturnNilWithErrorIfError(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
networkAclService := NetworkAclApi{
entityService: mockEntityService,
}
mockError := mocks.MockError{"some_create_vpc_error"}
mockEntityService.EXPECT().Create(gomock.Any(), gomock.Any()).Return(nil, mockError)
networkAclToCreate := NetworkAcl{Name: "new_name",
Description: "new_description",
VpcId: "vpcId"}
//when
createdNetworkAcl, err := networkAclService.Create(networkAclToCreate)
//then
assert.Nil(t, createdNetworkAcl)
assert.Equal(t, mockError, err)
}
示例8: TestListVpcOfferingReturnVpcsIfSuccess
func TestListVpcOfferingReturnVpcsIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
vpcOfferingService := VpcOfferingApi{
entityService: mockEntityService,
}
expectedVpcOffering1 := VpcOffering{Id: TEST_VPC_OFFERING_ID + "1",
Name: TEST_VPC_OFFERING_NAME + "1",
State: TEST_VPC_OFFERING_STATE + "1",
}
expectedVpcOfferings := []VpcOffering{expectedVpcOffering1}
mockEntityService.EXPECT().List(gomock.Any()).Return(buildListTestVpcOfferingJsonResponse(expectedVpcOfferings), nil)
//when
vpcOfferings, _ := vpcOfferingService.List()
//then
if assert.NotNil(t, vpcOfferings) {
assert.Equal(t, expectedVpcOfferings, vpcOfferings)
}
}
示例9: TestListZonesSuccess
func TestListZonesSuccess(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
assert := assert.New(t)
// given
mockEntityService := services_mocks.NewMockEntityService(ctrl)
zoneService := ZoneApi{
entityService: mockEntityService,
}
zone1 := Zone{
Id: "zoneid1",
Name: "zone1",
}
zone2 := Zone{
Id: "zoneid2",
Name: "zone2",
}
allZones := []Zone{zone1, zone2}
mockEntityService.EXPECT().List(gomock.Any()).Return([]byte(`[{"id":"zoneid1","name":"zone1"},{"id":"zoneid2","name":"zone2"}]`), nil)
// when
zones, err := zoneService.List()
// then
assert.Nil(err)
assert.Equal(zones, allZones)
}
示例10: TestCreateInstanceReturnNilWithErrorIfError
func TestCreateInstanceReturnNilWithErrorIfError(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
instanceService := InstanceApi{
entityService: mockEntityService,
}
mockError := mocks.MockError{"some_create_instance_error"}
mockEntityService.EXPECT().Create(gomock.Any(), gomock.Any()).Return(nil, mockError)
instanceToCreate := Instance{Name: "new_name",
TemplateId: "templateId",
ComputeOfferingId: "computeOfferingId",
NetworkId: "networkId"}
//when
createdInstance, err := instanceService.Create(instanceToCreate)
//then
assert.Nil(t, createdInstance)
assert.Equal(t, mockError, err)
}
示例11: TestPublicIpEnableStaticNatReturnFalseIfError
func TestPublicIpEnableStaticNatReturnFalseIfError(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
publicIpService := PublicIpApi{
entityService: mockEntityService,
}
publicIp := PublicIp{
Id: TEST_PUBLIC_IP_ID,
PrivateIpId: "private_ip_id",
}
mockError := mocks.MockError{"some_purge_instance_error"}
mockEntityService.EXPECT().Execute(TEST_PUBLIC_IP_ID, PUBLIC_IP_ENABLE_STATIC_NAT_OPERATION, gomock.Any(), gomock.Any()).Return([]byte(`{}`), mockError)
//when
success, err := publicIpService.EnableStaticNat(publicIp)
//then
assert.False(t, success)
assert.Equal(t, mockError, err)
}
示例12: TestCreateVpcReturnCreatedInstanceIfSuccess
func TestCreateVpcReturnCreatedInstanceIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
vpcService := VpcApi{
entityService: mockEntityService,
}
vpcToCreate := Vpc{Name: "new_name",
Description: "new_description",
VpcOfferingId: "vpc_offering_id",
}
mockEntityService.EXPECT().Create(gomock.Any(), gomock.Any()).Return([]byte(`{"id":"new_id"}`), nil)
//when
createdVpc, _ := vpcService.Create(vpcToCreate)
//then
if assert.NotNil(t, createdVpc) {
assert.Equal(t, "new_id", createdVpc.Id)
}
}
示例13: TestListNetworkAclReturnNetworkAclsIfSuccess
func TestListNetworkAclReturnNetworkAclsIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
networkAclService := NetworkAclApi{
entityService: mockEntityService,
}
expectedNetworkAcl1 := NetworkAcl{Id: "list_id_1",
Name: "list_name_1",
Description: "list_description_1",
VpcId: "list_vpc_id_1"}
expectedNetworkAcl2 := NetworkAcl{Id: "list_id_2",
Name: "list_name_2",
Description: "list_description_2",
VpcId: "list_vpc_id_2"}
expectedNetworkAcls := []NetworkAcl{expectedNetworkAcl1, expectedNetworkAcl2}
mockEntityService.EXPECT().List(gomock.Any()).Return(buildListTestNetworkAclsJsonResponse(expectedNetworkAcls), nil)
//when
networkAcls, _ := networkAclService.List()
//then
if assert.NotNil(t, networkAcls) {
assert.Equal(t, expectedNetworkAcls, networkAcls)
}
}
示例14: TestCreateVpcReturnNilWithErrorIfError
func TestCreateVpcReturnNilWithErrorIfError(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
vpcService := VpcApi{
entityService: mockEntityService,
}
mockError := mocks.MockError{"some_create_vpc_error"}
mockEntityService.EXPECT().Create(gomock.Any(), gomock.Any()).Return(nil, mockError)
vpcToCreate := Vpc{Name: "new_name",
Description: "new_description",
VpcOfferingId: "vpcOfferingId"}
//when
createdVpc, err := vpcService.Create(vpcToCreate)
//then
assert.Nil(t, createdVpc)
assert.Equal(t, mockError, err)
}
示例15: TestGetVolumeReturnVolumeIfSuccess
func TestGetVolumeReturnVolumeIfSuccess(t *testing.T) {
//given
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEntityService := services_mocks.NewMockEntityService(ctrl)
volumeService := VolumeApi{
entityService: mockEntityService,
}
expectedVolume := Volume{Id: TEST_VOLUME_ID,
Name: TEST_VOLUME_NAME,
Type: TEST_VOLUME_TYPE,
CreationDate: TEST_VOLUME_CREATION_DATE,
Size: TEST_VOLUME_SIZE,
DiskOfferingId: TEST_VOLUME_DISK_OFFERING_ID,
TemplateId: TEST_VOLUME_TEMPLATE_ID,
ZoneName: TEST_VOLUME_ZONE_NAME,
State: TEST_VOLUME_STATE,
InstanceName: TEST_VOLUME_INSTANCE_NAME,
InstanceId: TEST_VOLUME_INSTANCE_ID,
InstanceState: TEST_VOLUME_INSTANCE_STATE}
mockEntityService.EXPECT().Get(TEST_VOLUME_ID, gomock.Any()).Return(buildVolumeJsonResponse(&expectedVolume), nil)
//when
volume, _ := volumeService.Get(TEST_VOLUME_ID)
//then
if assert.NotNil(t, volume) {
assert.Equal(t, expectedVolume, *volume)
}
}