예제 #1
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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)
	}
}
예제 #16
0
func TestGetVpcReturnVpcIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	vpcService := VpcApi{
		entityService: mockEntityService,
	}

	expectedVpc := Vpc{Id: TEST_VPC_ID,
		Name:          TEST_VPC_NAME,
		Description:   TEST_VPC_DESCRIPTION,
		State:         TEST_VPC_STATE,
		Cidr:          TEST_VPC_CIDR,
		ZoneId:        TEST_VPC_ZONE_ID,
		ZoneName:      TEST_VPC_ZONE_NAME,
		NetworkDomain: TEST_VPC_NETWORK_DOMAIN,
		SourceNatIp:   TEST_VPC_SOURCE_NAT_IP,
		VpnStatus:     TEST_VPC_VPN_STATUS,
		Type:          TEST_VPC_TYPE,
		VpcOfferingId: TEST_VPC_VPC_OFFERING_ID,
	}

	mockEntityService.EXPECT().Get(TEST_VPC_ID, gomock.Any()).Return(buildTestVpcJsonResponse(&expectedVpc), nil)

	//when
	vpc, _ := vpcService.Get(TEST_VPC_ID)

	//then
	if assert.NotNil(t, vpc) {
		assert.Equal(t, expectedVpc, *vpc)
	}
}
예제 #17
0
func TestListDiskOfferingReturnDiskOfferingsIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	diskOfferingService := DiskOfferingApi{
		entityService: mockEntityService,
	}

	expectedDiskOfferings := []DiskOffering{
		DiskOffering{
			Id:     "list_id_1",
			Name:   "list_name_1",
			GbSize: 51,
		},
		DiskOffering{
			Id:     "list_id_2",
			Name:   "list_name_2",
			GbSize: 52,
		},
	}

	mockEntityService.EXPECT().List(gomock.Any()).Return(buildListDiskOfferingJsonResponse(expectedDiskOfferings), nil)

	//when
	diskOfferings, _ := diskOfferingService.List()

	//then
	if assert.NotNil(t, diskOfferings) {
		assert.Equal(t, expectedDiskOfferings, diskOfferings)
	}
}
예제 #18
0
func TestGetDiskOfferingReturnDiskOfferingIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	diskOfferingService := DiskOfferingApi{
		entityService: mockEntityService,
	}

	expectedDiskOffering := DiskOffering{Id: TEST_DISK_OFFERING_ID,
		Name:   TEST_DISK_OFFERING_NAME,
		GbSize: TEST_DISK_OFFERING_GBSIZE}

	mockEntityService.EXPECT().Get(TEST_DISK_OFFERING_ID, gomock.Any()).Return(buildDiskOfferingJsonResponse(&expectedDiskOffering), nil)

	//when
	diskOffering, _ := diskOfferingService.Get(TEST_DISK_OFFERING_ID)

	//then
	if assert.NotNil(t, diskOffering) {
		assert.Equal(t, expectedDiskOffering, *diskOffering)
	}
}
예제 #19
0
func TestGetVpcOfferingReturnVpcOfferingIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	vpcOfferingService := VpcOfferingApi{
		entityService: mockEntityService,
	}

	expectedVpcOffering := VpcOffering{Id: TEST_VPC_OFFERING_ID,
		Name:  TEST_VPC_OFFERING_NAME,
		State: TEST_VPC_OFFERING_STATE,
	}

	mockEntityService.EXPECT().Get(TEST_VPC_OFFERING_ID, gomock.Any()).Return(buildTestVpcOfferingJsonResponse(&expectedVpcOffering), nil)

	//when
	vpcOffering, _ := vpcOfferingService.Get(TEST_VPC_OFFERING_ID)

	//then
	if assert.NotNil(t, vpcOffering) {
		assert.Equal(t, expectedVpcOffering, *vpcOffering)
	}
}
예제 #20
0
func TestCreateInstanceReturnCreatedInstanceIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	instanceService := InstanceApi{
		entityService: mockEntityService,
	}

	instanceToCreate := Instance{Id: "new_id",
		Name:              "new_name",
		TemplateId:        "templateId",
		ComputeOfferingId: "computeOfferingId",
		NetworkId:         "networkId"}

	mockEntityService.EXPECT().Create(gomock.Any(), gomock.Any()).Return([]byte(`{"id":"new_id", "password": "******"}`), nil)

	//when
	createdInstance, _ := instanceService.Create(instanceToCreate)

	//then
	if assert.NotNil(t, createdInstance) {
		assert.Equal(t, "new_password", createdInstance.Password)
	}
}
예제 #21
0
func TestGetNetworkAclReturnNetworkAclIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	networkAclService := NetworkAclApi{
		entityService: mockEntityService,
	}

	expectedNetworkAcl := NetworkAcl{Id: TEST_NETWORK_ACL_ID,
		Name:        TEST_NETWORK_ACL_NAME,
		Description: TEST_NETWORK_ACL_DESCRIPTION,
		VpcId:       TEST_NETWORK_ACL_VPC_ID}
	mockEntityService.EXPECT().Get(TEST_NETWORK_ACL_ID, gomock.Any()).Return(buildTestNetworkAclJsonResponse(&expectedNetworkAcl), nil)

	//when
	networkAcl, _ := networkAclService.Get(TEST_NETWORK_ACL_ID)

	//then
	if assert.NotNil(t, networkAcl) {
		assert.Equal(t, expectedNetworkAcl, *networkAcl)
	}
}
예제 #22
0
func TestListTierReturnTiersIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	tierService := TierApi{
		entityService: mockEntityService,
	}

	expectedTier1 := Tier{Id: "list_id_1",
		Name:              "list_name_1",
		ZoneId:            "list_zone_id_1",
		ZoneName:          "list_zone_name_1",
		Cidr:              "list_cidr_1",
		Type:              "list_type_1",
		Gateway:           "list_gateway_1",
		NetworkOfferingId: "list_network_offering_id_1",
		IsSystem:          true,
		VpcId:             "list_vpc_id_1",
		Domain:            "list_domain_1",
		DomainId:          "list_domain_id_1",
		Project:           "list_project_1",
		ProjectId:         "list_project_id_1",
		NetworkAclId:      "list_acl_id_1"}

	expectedTier2 := Tier{Id: "list_id_2",
		Name:              "list_name_2",
		ZoneId:            "list_zone_id_2",
		ZoneName:          "list_zone_name_2",
		Cidr:              "list_cidr_2",
		Type:              "list_type_2",
		Gateway:           "list_gateway_2",
		NetworkOfferingId: "list_network_offering_id_2",
		IsSystem:          false,
		VpcId:             "list_vpc_id_2",
		Domain:            "list_domain_2",
		DomainId:          "list_domain_id_2",
		Project:           "list_project_2",
		ProjectId:         "list_project_id_2",
		NetworkAclId:      "list_acl_id_2"}

	expectedTiers := []Tier{expectedTier1, expectedTier2}

	mockEntityService.EXPECT().List(gomock.Any()).Return(buildListTestTierJsonResponse(expectedTiers), nil)

	//when
	tiers, _ := tierService.List()

	//then
	if assert.NotNil(t, tiers) {
		assert.Equal(t, expectedTiers, tiers)
	}
}
예제 #23
0
func TestListTemplateReturnTemplatesIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	templateService := TemplateApi{
		entityService: mockEntityService,
	}

	expectedTemplate1 := Template{Id: "list_id_1",
		Name:          "list_name_1",
		Description:   "list_description_1",
		Size:          132123,
		IsPublic:      true,
		IsReady:       true,
		SSHKeyEnabled: true,
		Extractable:   true,
		OSType:        "list_os_type_1",
		OSTypeId:      "list_os_type_id_1",
		Hypervisor:    "list_hypervisor_1",
		Format:        "list_format_1",
		ZoneName:      "list_zone_name_1",
		ProjectId:     "list_project_id_1",
	}
	expectedTemplate2 := Template{Id: "list_id_2",
		Name:          "list_name_2",
		Description:   "list_description_2",
		Size:          4525,
		IsPublic:      false,
		IsReady:       false,
		SSHKeyEnabled: false,
		Extractable:   false,
		OSType:        "list_os_type_2",
		OSTypeId:      "list_os_type_id_2",
		Hypervisor:    "list_hypervisor_2",
		Format:        "list_format_2",
		ZoneName:      "list_zone_name_2",
		ProjectId:     "list_project_id_2",
	}

	expectedTemplates := []Template{expectedTemplate1, expectedTemplate2}

	mockEntityService.EXPECT().List(gomock.Any()).Return(buildListTemplateJsonResponse(expectedTemplates), nil)

	//when
	templates, _ := templateService.List()

	//then
	if assert.NotNil(t, templates) {
		assert.Equal(t, expectedTemplates, templates)
	}
}
예제 #24
0
func TestListVolumeReturnVolumesIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	volumeService := VolumeApi{
		entityService: mockEntityService,
	}

	expectedVolume1 := Volume{Id: "list_id_1",
		Name:           "list_name_1",
		Type:           "list_type_1",
		CreationDate:   "list_creation_date_1",
		Size:           1215,
		DiskOfferingId: "list_disk_offering_id_1",
		TemplateId:     "list_template_id_1",
		ZoneName:       "list_zone_name_1",
		State:          "list_state_1",
		InstanceName:   "list_instance_name_1",
		InstanceId:     "list_instance_id_1",
		InstanceState:  "list_instance_state_1"}
	expectedVolume2 := Volume{Id: "list_id_2",
		Name:           "list_name_2",
		Type:           "list_type_2",
		CreationDate:   "list_creation_date_2",
		Size:           54582,
		DiskOfferingId: "list_disk_offering_id_2",
		TemplateId:     "list_template_id_2",
		ZoneName:       "list_zone_name_2",
		State:          "list_state_2",
		InstanceName:   "list_instance_name_2",
		InstanceId:     "list_instance_id_2",
		InstanceState:  "list_instance_state_2"}

	expectedVolumes := []Volume{expectedVolume1, expectedVolume2}

	mockEntityService.EXPECT().List(gomock.Any()).Return(buildListVolumeJsonResponse(expectedVolumes), nil)

	//when
	volumes, _ := volumeService.List()

	//then
	if assert.NotNil(t, volumes) {
		assert.Equal(t, expectedVolumes, volumes)
	}
}
예제 #25
0
func TestListInstanceReturnInstancesIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	instanceService := InstanceApi{
		entityService: mockEntityService,
	}

	expectedInstance1 := Instance{Id: "list_id_1",
		Name:                "list_name_1",
		State:               "list_state_1",
		TemplateId:          "list_template_id_1",
		TemplateName:        "list_template_name_1",
		IsPasswordEnabled:   false,
		IsSSHKeyEnabled:     true,
		Username:            "******",
		ComputeOfferingId:   "list_compute_offering_id_1",
		ComputeOfferingName: "list_compute_offering_name_1",
		CpuCount:            2,
		MemoryInMB:          12425,
		ZoneId:              "list_zone_id_1",
		ZoneName:            "list_zone_name_1",
		ProjectId:           "list_project_id_1",
		NetworkId:           "list_network_id_1",
		NetworkName:         "list_network_name_1",
		MacAddress:          "list_mac_address_1",
		VolumeIdToAttach:    "list_volume_id_to_attach_1",
		IpAddress:           "list_ip_address_1",
		PublicKey:           "list_public_key_1",
		UserData:            "list_user_data_1"}

	expectedInstances := []Instance{expectedInstance1}

	mockEntityService.EXPECT().List(gomock.Any()).Return(buildListTestInstanceJsonResponse(expectedInstances), nil)

	//when
	instances, _ := instanceService.List()

	//then
	if assert.NotNil(t, instances) {
		assert.Equal(t, expectedInstances, instances)
	}
}
예제 #26
0
func TestCreateReturnsErrorIfErrorWhileCreating(t *testing.T) {
	// given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()
	mockEntityService := services_mocks.NewMockEntityService(ctrl)
	volumeService := VolumeApi{
		entityService: mockEntityService,
	}
	mockError := mocks.MockError{"creation error"}
	mockEntityService.EXPECT().Create(gomock.Any(), gomock.Any()).Return(nil, mockError)

	// when
	volume, err := volumeService.Create(Volume{})

	// then
	assert.Nil(t, volume)
	assert.Equal(t, mockError, err)
}
예제 #27
0
func TestGetInstanceReturnInstanceIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	instanceService := InstanceApi{
		entityService: mockEntityService,
	}

	expectedInstance := Instance{Id: TEST_INSTANCE_ID,
		Name:                TEST_INSTANCE_NAME,
		State:               TEST_INSTANCE_STATE,
		TemplateId:          TEST_INSTANCE_TEMPLATE_ID,
		TemplateName:        TEST_INSTANCE_TEMPLATE_NAME,
		IsPasswordEnabled:   TEST_INSTANCE_IS_PASSWORD_ENABLED,
		IsSSHKeyEnabled:     TEST_INSTANCE_IS_SSH_KEY_ENABLED,
		Username:            TEST_INSTANCE_USERNAME,
		ComputeOfferingId:   TEST_INSTANCE_COMPUTE_OFFERING_ID,
		ComputeOfferingName: TEST_INSTANCE_COMPUTE_OFFERING_NAME,
		CpuCount:            TEST_INSTANCE_CPU_NUMBER,
		MemoryInMB:          TEST_INSTANCE_MEMORY_IN_MB,
		ZoneId:              TEST_INSTANCE_ZONE_ID,
		ZoneName:            TEST_INSTANCE_ZONE_NAME,
		ProjectId:           TEST_INSTANCE_PROJECT_ID,
		NetworkId:           TEST_INSTANCE_NETWORK_ID,
		NetworkName:         TEST_INSTANCE_NETWORK_NAME,
		MacAddress:          TEST_INSTANCE_MAC_ADDRESS,
		IpAddress:           TEST_INSTANCE_IP_ADDRESS,
		VolumeIdToAttach:    TEST_INSTANCE_VOLUME_ID_TO_ATTACH,
		PublicKey:           TEST_INSTANCE_PUBLIC_KEY,
		UserData:            TEST_INSTANCE_USER_DATA}

	mockEntityService.EXPECT().Get(TEST_INSTANCE_ID, gomock.Any()).Return(buildTestInstanceJsonResponse(&expectedInstance), nil)

	//when
	instance, _ := instanceService.Get(TEST_INSTANCE_ID)

	//then
	if assert.NotNil(t, instance) {
		assert.Equal(t, expectedInstance, *instance)
	}
}
예제 #28
0
func TestRestartRouterReturnTrueIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	vpcService := VpcApi{
		entityService: mockEntityService,
	}

	mockEntityService.EXPECT().Execute(TEST_VPC_ID, VPC_RESTART_ROUTER_OPERATION, gomock.Any(), gomock.Any()).Return([]byte(`{}`), nil)

	//when
	success, _ := vpcService.RestartRouter(TEST_VPC_ID)

	//then
	assert.True(t, success)
}
예제 #29
0
func TestExistsReturnTrueIfInstanceExists(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	instanceService := InstanceApi{
		entityService: mockEntityService,
	}

	mockEntityService.EXPECT().Get(TEST_INSTANCE_ID, gomock.Any()).Return([]byte(`{"id": "foo"}`), nil)

	//when
	exists, _ := instanceService.Exists(TEST_INSTANCE_ID)

	//then
	assert.True(t, exists)
}
예제 #30
0
func TestDeleteReturnTrueIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockEntityService := services_mocks.NewMockEntityService(ctrl)

	networkAclService := NetworkAclApi{
		entityService: mockEntityService,
	}

	mockEntityService.EXPECT().Delete(gomock.Any(), gomock.Any(), gomock.Any()).Return([]byte(`{}`), nil)

	//when
	success, _ := networkAclService.Delete(TEST_NETWORK_ACL_ID)

	//then
	assert.True(t, success)
}