_, err := hardwareService.CreateObject(template) Expect(err).To(HaveOccurred()) } }) }) }) Context("#GetObject", func() { BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Hardware_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) }) It("sucessfully retrieves SoftLayer_Virtual_Guest instance", func() { hardware, err := hardwareService.GetObject("abcdefg") Expect(err).ToNot(HaveOccurred()) Expect(hardware.Id).To(Equal(123)) Expect(hardware.Hostname).To(Equal("softlayer")) Expect(hardware.Domain).To(Equal("testing.com")) Expect(hardware.BareMetalInstanceFlag).To(Equal(1)) Expect(hardware.GlobalIdentifier).To(Equal("abcdefg")) }) 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 _, err := hardwareService.GetObject("abcdefg")
_, err := hardwareService.CreateObject(template) Expect(err).To(HaveOccurred()) } }) }) }) Context("#GetObject", func() { BeforeEach(func() { fakeClient.FakeHttpClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Hardware_Service_createObject.json") Expect(err).ToNot(HaveOccurred()) }) It("sucessfully retrieves SoftLayer_Virtual_Guest instance", func() { hardware, err := hardwareService.GetObject(123456) Expect(err).ToNot(HaveOccurred()) Expect(hardware.Id).To(Equal(123456)) Expect(hardware.Hostname).To(Equal("fake.hostname")) Expect(hardware.Domain).To(Equal("fake.domain.com")) Expect(hardware.BareMetalInstanceFlag).To(Equal(0)) Expect(hardware.GlobalIdentifier).To(Equal("abcdefg")) }) 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 _, err := hardwareService.GetObject(123456)