func (fps *FakeProductPackageService) GetItemsByType(packageType string) ([]datatypes.SoftLayer_Product_Item, error) { response, _ := testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Product_Package_getItemsByType_virtual_server.json") productItems := []datatypes.SoftLayer_Product_Item{} json.Unmarshal(response, &productItems) return productItems, nil }
networkStorageAllowedHostService, err = fakeClient.GetSoftLayer_Network_Storage_Allowed_Host_Service() Expect(err).ToNot(HaveOccurred()) Expect(networkStorageAllowedHostService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := networkStorageAllowedHostService.GetName() Expect(name).To(Equal("SoftLayer_Network_Storage_Allowed_Host")) }) }) Context("#GetCredential", func() { BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Network_Storage_Allowed_Host_Service_getCredential.json") Expect(err).ToNot(HaveOccurred()) }) It("return the credential with allowed host id", func() { credential, err := networkStorageAllowedHostService.GetCredential(123456) Expect(err).NotTo(HaveOccurred()) Expect(credential).ToNot(BeNil()) Expect(credential.Username).To(Equal("fake-username")) Expect(credential.Password).To(Equal("fake-password")) }) Context("when HTTP client returns error codes 40x or 50x", func() { It("fails for error code 40x", func() { errorCodes := []int{400, 401, 499} for _, errorCode := range errorCodes {
Expect(err).ToNot(HaveOccurred()) Expect(virtualDiskImageService).ToNot(BeNil()) virtualDiskImage = datatypes.SoftLayer_Virtual_Disk_Image{} }) Context("#GetName", func() { It("returns the name for the service", func() { name := virtualDiskImageService.GetName() Expect(name).To(Equal("SoftLayer_Virtual_Disk_Image")) }) }) Context("#GetObject", func() { BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Virtual_Disk_Image_Service_getObject.json") Expect(err).ToNot(HaveOccurred()) }) It("gets the SoftLayer_Virtual_Disk_Image instance", func() { virtualDiskImage, err = virtualDiskImageService.GetObject(4868344) Expect(err).ToNot(HaveOccurred()) Expect(virtualDiskImage.Capacity).To(Equal(25)) Expect(virtualDiskImage.CreateDate).ToNot(BeNil()) Expect(virtualDiskImage.Description).To(Equal("yz-fabric-node-20140407-133340-856.softlayer.com")) Expect(virtualDiskImage.Id).To(Equal(4868344)) Expect(virtualDiskImage.ModifyDate).To(BeNil()) Expect(virtualDiskImage.Name).To(Equal("yz-fabric-node-20140407-133340-856.softlayer.com")) Expect(virtualDiskImage.ParentId).To(Equal(0)) Expect(virtualDiskImage.StorageRepositoryId).To(Equal(1105002)) Expect(virtualDiskImage.TypeId).To(Equal(241))
productPackageService, err = fakeClient.GetSoftLayer_Product_Package_Service() Expect(err).ToNot(HaveOccurred()) Expect(productPackageService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := productPackageService.GetName() Expect(name).To(Equal("SoftLayer_Product_Package")) }) }) Context("#GetItemPrices", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Product_Package_getItemPrices.json") Expect(err).ToNot(HaveOccurred()) }) It("returns an array of datatypes.SoftLayer_Product_Item_Price", func() { itemPrices, err := productPackageService.GetItemPrices(0) Expect(err).ToNot(HaveOccurred()) Expect(len(itemPrices)).To(Equal(1)) Expect(itemPrices[0].Id).To(Equal(123)) Expect(itemPrices[0].Item.Id).To(Equal(456)) }) }) Context("#GetItemPricesBySize", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Product_Package_getItemPrices.json")
Expect(virtualGuestService).ToNot(BeNil()) virtualGuest = datatypes.SoftLayer_Virtual_Guest{} virtualGuestTemplate = datatypes.SoftLayer_Virtual_Guest_Template{} }) Context("#GetName", func() { It("returns the name for the service", func() { name := virtualGuestService.GetName() Expect(name).To(Equal("SoftLayer_Virtual_Guest")) }) }) Context("#CreateObject", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Virtual_Guest_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) }) It("creates a new SoftLayer_Virtual_Guest instance", func() { virtualGuestTemplate = datatypes.SoftLayer_Virtual_Guest_Template{ Hostname: "fake-hostname", Domain: "fake.domain.com", StartCpus: 2, MaxMemory: 1024, Datacenter: datatypes.Datacenter{ Name: "fake-datacenter-name", }, HourlyBillingFlag: true, LocalDiskFlag: false, DedicatedAccountHostOnlyFlag: false,
productOrderService, err = fakeClient.GetSoftLayer_Product_Order_Service() Expect(err).ToNot(HaveOccurred()) Expect(productOrderService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := productOrderService.GetName() Expect(name).To(Equal("SoftLayer_Product_Order")) }) }) Context("#PlaceOrder", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Product_Order_placeOrder.json") Expect(err).ToNot(HaveOccurred()) }) It("returns an instance of datatypes.SoftLayer_Container_Product_Order_Receipt", func() { receipt, err := productOrderService.PlaceOrder(datatypes.SoftLayer_Container_Product_Order{}) Expect(err).ToNot(HaveOccurred()) Expect(receipt).ToNot(BeNil()) Expect(receipt.OrderId).To(Equal(123)) }) }) Context("#PlaceContainerOrderNetworkPerformanceStorageIscsi", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Product_Order_placeOrder.json") Expect(err).ToNot(HaveOccurred())
Expect(vgbdtgService).ToNot(BeNil()) vgbdtGroup = datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{} }) Context("#GetName", func() { It("returns the name for the service", func() { name := vgbdtgService.GetName() Expect(name).To(Equal("SoftLayer_Virtual_Guest_Block_Device_Template_Group")) }) }) Context("#GetObject", func() { BeforeEach(func() { vgbdtGroup.Id = 200150 fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service_getObject.json") Expect(err).ToNot(HaveOccurred()) }) It("sucessfully retrieves SoftLayer_Virtual_Guest_Block_Device_Template_Group instance", func() { vgbdtg, err := vgbdtgService.GetObject(vgbdtGroup.Id) Expect(err).ToNot(HaveOccurred()) Expect(vgbdtg.AccountId).To(Equal(278444)) Expect(vgbdtg.CreateDate).ToNot(BeNil()) Expect(vgbdtg.Id).To(Equal(vgbdtGroup.Id)) Expect(vgbdtg.Name).To(Equal("BOSH-eCPI-packer-centos-2014-08-12T15:54:16Z")) Expect(vgbdtg.Note).To(Equal("centos image created by packer at 2014-08-12T15:54:16Z")) Expect(vgbdtg.ParentId).To(BeNil()) Expect(vgbdtg.PublicFlag).To(Equal(0)) Expect(vgbdtg.StatusId).To(Equal(1)) Expect(vgbdtg.Summary).To(Equal("centos image created by packer at 2014-08-12T15:54:16Z"))
productPackageService, err = fakeClient.GetSoftLayer_Product_Package_Service() Expect(err).ToNot(HaveOccurred()) Expect(productPackageService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := productPackageService.GetName() Expect(name).To(Equal("SoftLayer_Product_Package")) }) }) Context("#GetItemPrices", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Product_Package_getItemPrices.json") Expect(err).ToNot(HaveOccurred()) }) It("returns an array of datatypes.SoftLayer_Item_Price", func() { itemPrices, err := productPackageService.GetItemPrices(0) Expect(err).ToNot(HaveOccurred()) Expect(len(itemPrices)).To(Equal(1)) Expect(itemPrices[0].Id).To(Equal(123)) Expect(itemPrices[0].Item.Id).To(Equal(456)) }) }) Context("#GetItemPricesBySize", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Product_Package_getItemPrices.json")
Expect(err).ToNot(HaveOccurred()) Expect(dnsDomainResourceRecordService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := dnsDomainResourceRecordService.GetName() Expect(name).To(Equal("SoftLayer_Dns_Domain_ResourceRecord")) }) }) Context("#CreateObject", func() { var template datatypes.SoftLayer_Dns_Domain_ResourceRecord_Template BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Dns_Domain_ResourceRecord_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) template = datatypes.SoftLayer_Dns_Domain_ResourceRecord_Template{ Data: "testData", DomainId: 123, Expire: 99999, Host: "testHost.com", Id: 111, Minimum: 1, MxPriority: 9, Refresh: 100, ResponsiblePerson: "someTestPerson", Retry: 444, Ttl: 222, Type: "someTestType",
billingItemCancellationRequestService, err = fakeClient.GetSoftLayer_Billing_Item_Cancellation_Request_Service() Expect(err).ToNot(HaveOccurred()) Expect(billingItemCancellationRequestService).ToNot(BeNil()) }) Context("#GetNam", func() { It("returns the name for the service", func() { name := billingItemCancellationRequestService.GetName() Expect(name).To(Equal("SoftLayer_Billing_Item_Cancellation_Request")) }) }) Context("#CreateObject", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Billing_Item_Cancellation_Request_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) }) It("returns an instance of datatypes.SoftLayer_Network_Storage", func() { request := datatypes.SoftLayer_Billing_Item_Cancellation_Request{} result, err := billingItemCancellationRequestService.CreateObject(request) Expect(err).ToNot(HaveOccurred()) Expect(result.Id).To(Equal(123)) Expect(result.AccountId).To(Equal(456)) Expect(result.TicketId).To(Equal(789)) }) }) })
Expect(err).ToNot(HaveOccurred()) Expect(hardwareService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := hardwareService.GetName() Expect(name).To(Equal("SoftLayer_Hardware")) }) }) Context("#CreateObject", func() { var template datatypes.SoftLayer_Hardware_Template BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Hardware_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) template = datatypes.SoftLayer_Hardware_Template{ Hostname: "softlayer", Domain: "testing.com", ProcessorCoreAmount: 2, MemoryCapacity: 2, HourlyBillingFlag: true, OperatingSystemReferenceCode: "UBUNTU_LATEST", Datacenter: &datatypes.Datacenter{ Name: "ams01", }, } })
volume = datatypes.SoftLayer_Network_Storage{} }) Context("#GetName", func() { It("returns the name for the service", func() { name := hardwareService.GetName() Expect(name).To(Equal("SoftLayer_Hardware")) }) }) Context("#CreateObject", func() { var template datatypes.SoftLayer_Hardware_Template BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Hardware_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) template = datatypes.SoftLayer_Hardware_Template{ Hostname: "softlayer", Domain: "testing.com", ProcessorCoreAmount: 2, MemoryCapacity: 2, HourlyBillingFlag: true, OperatingSystemReferenceCode: "UBUNTU_LATEST", Datacenter: &datatypes.Datacenter{ Name: "ams01", }, } })
Expect(sshKeyService).ToNot(BeNil()) sshKey = datatypes.SoftLayer_Security_Ssh_Key{} sshKeyTemplate = datatypes.SoftLayer_Security_Ssh_Key{} }) Context("#GetName", func() { It("returns the name for the service", func() { name := sshKeyService.GetName() Expect(name).To(Equal("SoftLayer_Security_Ssh_Key")) }) }) Context("#CreateObject", func() { BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Security_Ssh_Key_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) }) It("creates a new SoftLayer_Ssh_Key instance", func() { sshKeyTemplate = datatypes.SoftLayer_Security_Ssh_Key{ Fingerprint: "fake-fingerprint", Key: "fake-key", Label: "fake-label", Notes: "fake-notes", } sshKey, err = sshKeyService.CreateObject(sshKeyTemplate) Expect(err).ToNot(HaveOccurred()) Expect(sshKey.Fingerprint).To(Equal("fake-fingerprint")) Expect(sshKey.Key).To(Equal("fake-key")) Expect(sshKey.Label).To(Equal("fake-label"))
dnsDomainService, err = fakeClient.GetSoftLayer_Dns_Domain_Service() Expect(err).ToNot(HaveOccurred()) Expect(dnsDomainService).NotTo(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := dnsDomainService.GetName() Expect(name).To(Equal("SoftLayer_Dns_Domain")) }) }) Context("#CreateDns", func() { BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Dns_Domain_createObject.json") Expect(err).ToNot(HaveOccurred()) }) It("returns an instance of datatypes.SoftLayer_Dns_Domain", func() { dns, err := dnsDomainService.CreateObject(datatypes.SoftLayer_Dns_Domain_Template{}) Expect(err).ToNot(HaveOccurred()) Expect(dns).NotTo(BeNil()) Expect(dns.Id).NotTo(BeNil()) Expect(dns.Serial).NotTo(BeNil()) Expect(dns.UpdateDate).NotTo(BeNil()) Expect(dns.Name).To(Equal("qwerty123ff.com")) }) Context("when HTTP client returns error codes 40x or 50x", func() { It("fails for error code 40x", func() {
networkStorageService, err = fakeClient.GetSoftLayer_Network_Storage_Service() Expect(err).ToNot(HaveOccurred()) Expect(networkStorageService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := networkStorageService.GetName() Expect(name).To(Equal("SoftLayer_Network_Storage")) }) }) Context("#CreateIscsiVolume", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Network_Storage_Service_getIscsiVolume.json") Expect(err).ToNot(HaveOccurred()) }) It("fails with error if the volume size is negative", func() { _, err := networkStorageService.CreateIscsiVolume(-1, "fake-location") Expect(err).To(HaveOccurred()) }) }) Context("#GetIscsiVolume", func() { BeforeEach(func() { fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Network_Storage_Service_getIscsiVolume.json") Expect(err).ToNot(HaveOccurred()) }) It("returns the iSCSI volume object based on volume id", func() {
LongName: "Location 2", }, } }) Context("#GetName", func() { It("returns the name for the service", func() { name := vgbdtgService.GetName() Expect(name).To(Equal("SoftLayer_Virtual_Guest_Block_Device_Template_Group")) }) }) Context("#GetObject", func() { BeforeEach(func() { vgbdtGroup.Id = 200150 fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service_getObject.json") Expect(err).ToNot(HaveOccurred()) }) It("sucessfully retrieves SoftLayer_Virtual_Guest_Block_Device_Template_Group instance", func() { vgbdtg, err := vgbdtgService.GetObject(vgbdtGroup.Id) Expect(err).ToNot(HaveOccurred()) Expect(vgbdtg.AccountId).To(Equal(278444)) Expect(vgbdtg.CreateDate).ToNot(BeNil()) Expect(vgbdtg.Id).To(Equal(vgbdtGroup.Id)) Expect(vgbdtg.Name).To(Equal("BOSH-eCPI-packer-centos-2014-08-12T15:54:16Z")) Expect(vgbdtg.Note).To(Equal("centos image created by packer at 2014-08-12T15:54:16Z")) Expect(vgbdtg.ParentId).To(BeNil()) Expect(vgbdtg.PublicFlag).To(Equal(0)) Expect(vgbdtg.StatusId).To(Equal(1)) Expect(vgbdtg.Summary).To(Equal("centos image created by packer at 2014-08-12T15:54:16Z"))
accountService, err = fakeClient.GetSoftLayer_Account_Service() Expect(err).ToNot(HaveOccurred()) Expect(accountService).ToNot(BeNil()) }) Context("#GetName", func() { It("returns the name for the service", func() { name := accountService.GetName() Expect(name).To(Equal("SoftLayer_Account")) }) }) Context("#GetAccountStatus", func() { BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Account_Service_getAccountStatus.json") Expect(err).ToNot(HaveOccurred()) }) It("returns an instance of datatypes.SoftLayer_Account_Status that is Active", func() { accountStatus, err := accountService.GetAccountStatus() Expect(err).ToNot(HaveOccurred()) Expect(accountStatus.Id).ToNot(Equal(0)) Expect(accountStatus.Name).To(Equal("Active")) }) Context("when HTTP client returns error codes 40x or 50x", func() { It("fails for error code 40x", func() { errorCodes := []int{400, 401, 499} for _, errorCode := range errorCodes { fakeClient.FakeHttpClient.DoRawHttpRequestInt = errorCode