BeforeEach(func() {
		softLayerClient = fakeslclient.NewFakeSoftLayerClient("fake-username", "fake-api-key")
		uuidGenerator = fakeuuid.NewFakeGenerator()
		fs = fakesys.NewFakeFileSystem()
		agentEnvServiceFactory = &fakevm.FakeAgentEnvServiceFactory{}
		logger = boshlog.NewLogger(boshlog.LevelNone)

		finder = NewSoftLayerFinder(
			softLayerClient,
			agentEnvServiceFactory,
			logger,
			uuidGenerator,
			fs,
		)

		testhelpers.SetTestFixtureForFakeSoftLayerClient(softLayerClient, "SoftLayer_Virtual_Guest_Service_getObject.json")
	})

	Describe("Find", func() {
		var (
			vmID int
		)

		Context("when the VM ID is valid and existing", func() {
			BeforeEach(func() {
				vmID = 1234567
			})

			It("finds and returns a new SoftLayerVM object with correct ID", func() {
				vm, found, err := finder.Find(vmID)
				Expect(err).ToNot(HaveOccurred())
	)

	BeforeEach(func() {
		softLayerClient = fakeslclient.NewFakeSoftLayerClient("fake-username", "fake-api-key")
		logger = boshlog.NewLogger(boshlog.LevelNone)

		finder = bm.NewBaremetalFinder(
			softLayerClient,
			logger,
		)
	})

	Describe("Find", func() {
		Context("succeeded", func() {
			BeforeEach(func() {
				testhelpers.SetTestFixtureForFakeSoftLayerClient(softLayerClient, "SoftLayer_Hardware_Service_getObject.json")
			})

			It("returns a new Softlayer Hardware without an error", func() {
				baremetal, err := finder.Find("fake-id")
				Expect(err).ToNot(HaveOccurred())
				Expect(baremetal.GlobalIdentifier).To(Equal("fake-id"))
				Expect(baremetal.BareMetalInstanceFlag).To(Equal(1))
				Expect(baremetal.ProvisionDate).ToNot(BeNil())
				Expect(baremetal.PrimaryIpAddress).To(Equal("1.1.1.1"))
			})
		})

		Context("failed", func() {
			BeforeEach(func() {
				testhelpers.SetTestFixtureForFakeSoftLayerClient(softLayerClient, "SoftLayer_Hardware_Service_getObject_None_Exist.json")
var _ = Describe("SoftLayerFinder", func() {
	var (
		fc     *fakeclient.FakeSoftLayerClient
		logger boshlog.Logger
		finder SoftLayerFinder
	)

	BeforeEach(func() {
		fc = fakeclient.NewFakeSoftLayerClient("fake-user", "fake-key")
		logger = boshlog.NewLogger(boshlog.LevelNone)
		finder = NewSoftLayerDiskFinder(fc, logger)
	})

	Describe("Find", func() {
		It("returns disk and found as true when found the disk successfully", func() {
			testhelpers.SetTestFixtureForFakeSoftLayerClient(fc, "SoftLayer_Network_Storage_Service_getIscsiVolume.json")

			disk, found, err := finder.Find(1234)
			Expect(err).ToNot(HaveOccurred())
			Expect(found).To(BeTrue())

			expectedDisk := NewSoftLayerDisk(1234, fc, logger)
			Expect(disk).To(Equal(expectedDisk))
		})

		It("returns found as false when failed to find the disk", func() {
			testhelpers.SetTestFixtureForFakeSoftLayerClient(fc, "SoftLayer_Network_Storage_Service_getEmptyIscsiVolume.json")
			disk, found, err := finder.Find(1234)

			Expect(err).ToNot(HaveOccurred())
			Expect(found).To(BeFalse())
var _ = Describe("BaremetalCreator", func() {
	var (
		softLayerClient *fakeslclient.FakeSoftLayerClient
		logger          boshlog.Logger
		creator         bm.BaremetalCreator
	)

	BeforeEach(func() {
		softLayerClient = fakeslclient.NewFakeSoftLayerClient("fake-username", "fake-api-key")
		logger = boshlog.NewLogger(boshlog.LevelNone)

		creator = bm.NewBaremetalCreator(
			softLayerClient,
			logger,
		)
		testhelpers.SetTestFixtureForFakeSoftLayerClient(softLayerClient, "SoftLayer_Hardware_Service_createObject.json")
	})

	Describe("Create", func() {
		Context("succeeded", func() {
			It("returns a new Softlayer Hardware without an error", func() {
				baremetal, err := creator.Create(2, 1, 10, "fake-host", "fake-domain", "fake-os", "fake-data-center")
				Expect(err).ToNot(HaveOccurred())
				Expect(baremetal.GlobalIdentifier).To(Equal("fake-id"))
				Expect(baremetal.BareMetalInstanceFlag).To(Equal(0))
				Expect(baremetal.ProvisionDate).To(BeNil())
				Expect(baremetal.PrimaryIpAddress).To(Equal(""))
			})
		})

		Context("failed", func() {
	boshlog "github.com/cloudfoundry/bosh-utils/logger"

	fakesslclient "github.com/maximilien/softlayer-go/client/fakes"
)

var _ = Describe("SoftLayerFinder", func() {
	var (
		softLayerClient  *fakesslclient.FakeSoftLayerClient
		logger           boshlog.Logger
		finder           SoftLayerFinder
		expectedStemcell SoftLayerStemcell
	)

	BeforeEach(func() {
		softLayerClient = fakesslclient.NewFakeSoftLayerClient("fake-username", "fake-api-key")
		testhelpers.SetTestFixtureForFakeSoftLayerClient(softLayerClient, "SoftLayer_Account_Service_getVirtualDiskImages.json")

		logger = boshlog.NewLogger(boshlog.LevelNone)
		finder = NewSoftLayerFinder(softLayerClient, logger)

		expectedStemcell = NewSoftLayerStemcell(4868344, "8c7a8358-d9a9-4e4d-9345-6f637e10ccb7", VirtualDiskImageKind, softLayerClient, logger)
	})

	Describe("Find", func() {
		Context("valid stemcell UUID pointing to a SL virtual disk image", func() {
			It("returns stemcell and found as true if stemcell exists", func() {
				stemcell, found, err := finder.Find("8c7a8358-d9a9-4e4d-9345-6f637e10ccb7")
				Expect(err).ToNot(HaveOccurred())
				Expect(found).To(BeTrue())
				Expect(stemcell).To(Equal(expectedStemcell))
			})