From 617276ed24fcc713df3a6bcd1294c6dc0da03608 Mon Sep 17 00:00:00 2001 From: Shatarupa Nandi Date: Wed, 10 May 2017 17:06:52 -0700 Subject: [PATCH] rename to OrphanDisk --- bin/gen-fakes | 2 +- cmd/delete_disk.go | 2 +- cmd/delete_disk_test.go | 16 +- cmd/disks.go | 2 +- cmd/disks_test.go | 8 +- cmd/orphan_disk.go | 2 +- cmd/orphan_disk_test.go | 11 +- director/directorfakes/fake_director.go | 150 +++++++++--------- ...e_orphaned_disk.go => fake_orphan_disk.go} | 50 +++--- director/interfaces.go | 10 +- .../{orphaned_disks.go => orphan_disks.go} | 63 +++----- ...ned_disks_test.go => orphan_disks_test.go} | 76 ++------- 12 files changed, 160 insertions(+), 232 deletions(-) rename director/directorfakes/{fake_orphaned_disk.go => fake_orphan_disk.go} (79%) rename director/{orphaned_disks.go => orphan_disks.go} (59%) rename director/{orphaned_disks_test.go => orphan_disks_test.go} (74%) diff --git a/bin/gen-fakes b/bin/gen-fakes index b0eea20b9..da3959f95 100755 --- a/bin/gen-fakes +++ b/bin/gen-fakes @@ -26,7 +26,7 @@ counterfeiter director ReleaseArchive counterfeiter director Stemcell counterfeiter director StemcellArchive counterfeiter director Task -counterfeiter director OrphanedDisk +counterfeiter director OrphanDisk counterfeiter director FileReporter counterfeiter director TaskReporter counterfeiter director Event diff --git a/cmd/delete_disk.go b/cmd/delete_disk.go index f2868521b..2ca510ddc 100644 --- a/cmd/delete_disk.go +++ b/cmd/delete_disk.go @@ -20,7 +20,7 @@ func (c DeleteDiskCmd) Run(opts DeleteDiskOpts) error { return err } - disk, err := c.director.FindOrphanedDisk(opts.Args.CID) + disk, err := c.director.FindOrphanDisk(opts.Args.CID) if err != nil { return err } diff --git a/cmd/delete_disk_test.go b/cmd/delete_disk_test.go index 8e28c769e..69c54bd31 100644 --- a/cmd/delete_disk_test.go +++ b/cmd/delete_disk_test.go @@ -38,19 +38,19 @@ var _ = Describe("DeleteDiskCmd", func() { act := func() error { return command.Run(opts) } It("deletes orphaned disk", func() { - disk := &fakedir.FakeOrphanedDisk{} - director.FindOrphanedDiskReturns(disk, nil) + disk := &fakedir.FakeOrphanDisk{} + director.FindOrphanDiskReturns(disk, nil) err := act() Expect(err).ToNot(HaveOccurred()) - Expect(director.FindOrphanedDiskArgsForCall(0)).To(Equal("disk-cid")) + Expect(director.FindOrphanDiskArgsForCall(0)).To(Equal("disk-cid")) Expect(disk.DeleteCallCount()).To(Equal(1)) }) It("returns error if deleting disk failed", func() { - disk := &fakedir.FakeOrphanedDisk{} - director.FindOrphanedDiskReturns(disk, nil) + disk := &fakedir.FakeOrphanDisk{} + director.FindOrphanDiskReturns(disk, nil) disk.DeleteReturns(errors.New("fake-err")) @@ -60,8 +60,8 @@ var _ = Describe("DeleteDiskCmd", func() { }) It("does not delete disk if confirmation is rejected", func() { - disk := &fakedir.FakeOrphanedDisk{} - director.FindOrphanedDiskReturns(disk, nil) + disk := &fakedir.FakeOrphanDisk{} + director.FindOrphanDiskReturns(disk, nil) ui.AskedConfirmationErr = errors.New("stop") @@ -73,7 +73,7 @@ var _ = Describe("DeleteDiskCmd", func() { }) It("returns error if finding disk failed", func() { - director.FindOrphanedDiskReturns(nil, errors.New("fake-err")) + director.FindOrphanDiskReturns(nil, errors.New("fake-err")) err := act() Expect(err).To(HaveOccurred()) diff --git a/cmd/disks.go b/cmd/disks.go index ca0db8363..d27933d05 100644 --- a/cmd/disks.go +++ b/cmd/disks.go @@ -22,7 +22,7 @@ func (c DisksCmd) Run(opts DisksOpts) error { return errors.New("Only --orphaned is supported") } - disks, err := c.director.OrphanedDisks() + disks, err := c.director.OrphanDisks() if err != nil { return err } diff --git a/cmd/disks_test.go b/cmd/disks_test.go index cfab34b8f..0f8d2b485 100644 --- a/cmd/disks_test.go +++ b/cmd/disks_test.go @@ -44,8 +44,8 @@ var _ = Describe("DisksCmd", func() { }) It("lists disks", func() { - disks := []boshdir.OrphanedDisk{ - &fakedir.FakeOrphanedDisk{ + disks := []boshdir.OrphanDisk{ + &fakedir.FakeOrphanDisk{ CIDStub: func() string { return "cid" }, SizeStub: func() uint64 { return 100 }, @@ -63,7 +63,7 @@ var _ = Describe("DisksCmd", func() { }, } - director.OrphanedDisksReturns(disks, nil) + director.OrphanDisksReturns(disks, nil) err := act() Expect(err).ToNot(HaveOccurred()) @@ -96,7 +96,7 @@ var _ = Describe("DisksCmd", func() { }) It("returns error if orphaned disks cannot be retrieved", func() { - director.OrphanedDisksReturns(nil, errors.New("fake-err")) + director.OrphanDisksReturns(nil, errors.New("fake-err")) err := act() Expect(err).To(HaveOccurred()) diff --git a/cmd/orphan_disk.go b/cmd/orphan_disk.go index 8c51cda8d..640d024e9 100644 --- a/cmd/orphan_disk.go +++ b/cmd/orphan_disk.go @@ -20,5 +20,5 @@ func (c OrphanDiskCmd) Run(opts OrphanDiskOpts) error { return err } - return c.director.Orphan(opts.Args.CID) + return c.director.OrphanDisk(opts.Args.CID) } diff --git a/cmd/orphan_disk_test.go b/cmd/orphan_disk_test.go index 22a864d6d..8cf061c8b 100644 --- a/cmd/orphan_disk_test.go +++ b/cmd/orphan_disk_test.go @@ -38,17 +38,15 @@ var _ = Describe("OrphanDiskCmd", func() { act := func() error { return command.Run(opts) } It("orphans disk", func() { - err := act() Expect(err).ToNot(HaveOccurred()) - Expect(director.OrphanArgsForCall(0)).To(Equal("disk-cid")) - Expect(director.OrphanCallCount()).To(Equal(1)) + Expect(director.OrphanDiskArgsForCall(0)).To(Equal("disk-cid")) + Expect(director.OrphanDiskCallCount()).To(Equal(1)) }) It("returns error if orphaning disk failed", func() { - - director.OrphanReturns(errors.New("fake-err")) + director.OrphanDiskReturns(errors.New("fake-err")) err := act() Expect(err).To(HaveOccurred()) @@ -56,14 +54,13 @@ var _ = Describe("OrphanDiskCmd", func() { }) It("does not orphan disk if confirmation is rejected", func() { - ui.AskedConfirmationErr = errors.New("stop") err := act() Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("stop")) - Expect(director.OrphanCallCount()).To(Equal(0)) + Expect(director.OrphanDiskCallCount()).To(Equal(0)) }) }) }) diff --git a/director/directorfakes/fake_director.go b/director/directorfakes/fake_director.go index e04da1cbc..946330f7f 100644 --- a/director/directorfakes/fake_director.go +++ b/director/directorfakes/fake_director.go @@ -277,28 +277,28 @@ type FakeDirector struct { updateRuntimeConfigReturns struct { result1 error } - FindOrphanedDiskStub func(string) (director.OrphanedDisk, error) - findOrphanedDiskMutex sync.RWMutex - findOrphanedDiskArgsForCall []struct { + FindOrphanDiskStub func(string) (director.OrphanDisk, error) + findOrphanDiskMutex sync.RWMutex + findOrphanDiskArgsForCall []struct { arg1 string } - findOrphanedDiskReturns struct { - result1 director.OrphanedDisk + findOrphanDiskReturns struct { + result1 director.OrphanDisk result2 error } - OrphanedDisksStub func() ([]director.OrphanedDisk, error) - orphanedDisksMutex sync.RWMutex - orphanedDisksArgsForCall []struct{} - orphanedDisksReturns struct { - result1 []director.OrphanedDisk + OrphanDisksStub func() ([]director.OrphanDisk, error) + orphanDisksMutex sync.RWMutex + orphanDisksArgsForCall []struct{} + orphanDisksReturns struct { + result1 []director.OrphanDisk result2 error } - OrphanStub func(string) error - orphanMutex sync.RWMutex - orphanArgsForCall []struct { + OrphanDiskStub func(string) error + orphanDiskMutex sync.RWMutex + orphanDiskArgsForCall []struct { arg1 string } - orphanReturns struct { + orphanDiskReturns struct { result1 error } EnableResurrectionStub func(bool) error @@ -1314,92 +1314,92 @@ func (fake *FakeDirector) UpdateRuntimeConfigReturns(result1 error) { }{result1} } -func (fake *FakeDirector) FindOrphanedDisk(arg1 string) (director.OrphanedDisk, error) { - fake.findOrphanedDiskMutex.Lock() - fake.findOrphanedDiskArgsForCall = append(fake.findOrphanedDiskArgsForCall, struct { +func (fake *FakeDirector) FindOrphanDisk(arg1 string) (director.OrphanDisk, error) { + fake.findOrphanDiskMutex.Lock() + fake.findOrphanDiskArgsForCall = append(fake.findOrphanDiskArgsForCall, struct { arg1 string }{arg1}) - fake.recordInvocation("FindOrphanedDisk", []interface{}{arg1}) - fake.findOrphanedDiskMutex.Unlock() - if fake.FindOrphanedDiskStub != nil { - return fake.FindOrphanedDiskStub(arg1) + fake.recordInvocation("FindOrphanDisk", []interface{}{arg1}) + fake.findOrphanDiskMutex.Unlock() + if fake.FindOrphanDiskStub != nil { + return fake.FindOrphanDiskStub(arg1) } - return fake.findOrphanedDiskReturns.result1, fake.findOrphanedDiskReturns.result2 + return fake.findOrphanDiskReturns.result1, fake.findOrphanDiskReturns.result2 } -func (fake *FakeDirector) FindOrphanedDiskCallCount() int { - fake.findOrphanedDiskMutex.RLock() - defer fake.findOrphanedDiskMutex.RUnlock() - return len(fake.findOrphanedDiskArgsForCall) +func (fake *FakeDirector) FindOrphanDiskCallCount() int { + fake.findOrphanDiskMutex.RLock() + defer fake.findOrphanDiskMutex.RUnlock() + return len(fake.findOrphanDiskArgsForCall) } -func (fake *FakeDirector) FindOrphanedDiskArgsForCall(i int) string { - fake.findOrphanedDiskMutex.RLock() - defer fake.findOrphanedDiskMutex.RUnlock() - return fake.findOrphanedDiskArgsForCall[i].arg1 +func (fake *FakeDirector) FindOrphanDiskArgsForCall(i int) string { + fake.findOrphanDiskMutex.RLock() + defer fake.findOrphanDiskMutex.RUnlock() + return fake.findOrphanDiskArgsForCall[i].arg1 } -func (fake *FakeDirector) FindOrphanedDiskReturns(result1 director.OrphanedDisk, result2 error) { - fake.FindOrphanedDiskStub = nil - fake.findOrphanedDiskReturns = struct { - result1 director.OrphanedDisk +func (fake *FakeDirector) FindOrphanDiskReturns(result1 director.OrphanDisk, result2 error) { + fake.FindOrphanDiskStub = nil + fake.findOrphanDiskReturns = struct { + result1 director.OrphanDisk result2 error }{result1, result2} } -func (fake *FakeDirector) OrphanedDisks() ([]director.OrphanedDisk, error) { - fake.orphanedDisksMutex.Lock() - fake.orphanedDisksArgsForCall = append(fake.orphanedDisksArgsForCall, struct{}{}) - fake.recordInvocation("OrphanedDisks", []interface{}{}) - fake.orphanedDisksMutex.Unlock() - if fake.OrphanedDisksStub != nil { - return fake.OrphanedDisksStub() +func (fake *FakeDirector) OrphanDisks() ([]director.OrphanDisk, error) { + fake.orphanDisksMutex.Lock() + fake.orphanDisksArgsForCall = append(fake.orphanDisksArgsForCall, struct{}{}) + fake.recordInvocation("OrphanDisks", []interface{}{}) + fake.orphanDisksMutex.Unlock() + if fake.OrphanDisksStub != nil { + return fake.OrphanDisksStub() } - return fake.orphanedDisksReturns.result1, fake.orphanedDisksReturns.result2 + return fake.orphanDisksReturns.result1, fake.orphanDisksReturns.result2 } -func (fake *FakeDirector) OrphanedDisksCallCount() int { - fake.orphanedDisksMutex.RLock() - defer fake.orphanedDisksMutex.RUnlock() - return len(fake.orphanedDisksArgsForCall) +func (fake *FakeDirector) OrphanDisksCallCount() int { + fake.orphanDisksMutex.RLock() + defer fake.orphanDisksMutex.RUnlock() + return len(fake.orphanDisksArgsForCall) } -func (fake *FakeDirector) OrphanedDisksReturns(result1 []director.OrphanedDisk, result2 error) { - fake.OrphanedDisksStub = nil - fake.orphanedDisksReturns = struct { - result1 []director.OrphanedDisk +func (fake *FakeDirector) OrphanDisksReturns(result1 []director.OrphanDisk, result2 error) { + fake.OrphanDisksStub = nil + fake.orphanDisksReturns = struct { + result1 []director.OrphanDisk result2 error }{result1, result2} } -func (fake *FakeDirector) Orphan(arg1 string) error { - fake.orphanMutex.Lock() - fake.orphanArgsForCall = append(fake.orphanArgsForCall, struct { +func (fake *FakeDirector) OrphanDisk(arg1 string) error { + fake.orphanDiskMutex.Lock() + fake.orphanDiskArgsForCall = append(fake.orphanDiskArgsForCall, struct { arg1 string }{arg1}) - fake.recordInvocation("Orphan", []interface{}{arg1}) - fake.orphanMutex.Unlock() - if fake.OrphanStub != nil { - return fake.OrphanStub(arg1) + fake.recordInvocation("OrphanDisk", []interface{}{arg1}) + fake.orphanDiskMutex.Unlock() + if fake.OrphanDiskStub != nil { + return fake.OrphanDiskStub(arg1) } - return fake.orphanReturns.result1 + return fake.orphanDiskReturns.result1 } -func (fake *FakeDirector) OrphanCallCount() int { - fake.orphanMutex.RLock() - defer fake.orphanMutex.RUnlock() - return len(fake.orphanArgsForCall) +func (fake *FakeDirector) OrphanDiskCallCount() int { + fake.orphanDiskMutex.RLock() + defer fake.orphanDiskMutex.RUnlock() + return len(fake.orphanDiskArgsForCall) } -func (fake *FakeDirector) OrphanArgsForCall(i int) string { - fake.orphanMutex.RLock() - defer fake.orphanMutex.RUnlock() - return fake.orphanArgsForCall[i].arg1 +func (fake *FakeDirector) OrphanDiskArgsForCall(i int) string { + fake.orphanDiskMutex.RLock() + defer fake.orphanDiskMutex.RUnlock() + return fake.orphanDiskArgsForCall[i].arg1 } -func (fake *FakeDirector) OrphanReturns(result1 error) { - fake.OrphanStub = nil - fake.orphanReturns = struct { +func (fake *FakeDirector) OrphanDiskReturns(result1 error) { + fake.OrphanDiskStub = nil + fake.orphanDiskReturns = struct { result1 error }{result1} } @@ -1566,12 +1566,12 @@ func (fake *FakeDirector) Invocations() map[string][][]interface{} { defer fake.latestRuntimeConfigMutex.RUnlock() fake.updateRuntimeConfigMutex.RLock() defer fake.updateRuntimeConfigMutex.RUnlock() - fake.findOrphanedDiskMutex.RLock() - defer fake.findOrphanedDiskMutex.RUnlock() - fake.orphanedDisksMutex.RLock() - defer fake.orphanedDisksMutex.RUnlock() - fake.orphanMutex.RLock() - defer fake.orphanMutex.RUnlock() + fake.findOrphanDiskMutex.RLock() + defer fake.findOrphanDiskMutex.RUnlock() + fake.orphanDisksMutex.RLock() + defer fake.orphanDisksMutex.RUnlock() + fake.orphanDiskMutex.RLock() + defer fake.orphanDiskMutex.RUnlock() fake.enableResurrectionMutex.RLock() defer fake.enableResurrectionMutex.RUnlock() fake.cleanUpMutex.RLock() diff --git a/director/directorfakes/fake_orphaned_disk.go b/director/directorfakes/fake_orphan_disk.go similarity index 79% rename from director/directorfakes/fake_orphaned_disk.go rename to director/directorfakes/fake_orphan_disk.go index ce0e22683..8ded9063b 100644 --- a/director/directorfakes/fake_orphaned_disk.go +++ b/director/directorfakes/fake_orphan_disk.go @@ -8,7 +8,7 @@ import ( "github.com/cloudfoundry/bosh-cli/director" ) -type FakeOrphanedDisk struct { +type FakeOrphanDisk struct { CIDStub func() string cIDMutex sync.RWMutex cIDArgsForCall []struct{} @@ -55,7 +55,7 @@ type FakeOrphanedDisk struct { invocationsMutex sync.RWMutex } -func (fake *FakeOrphanedDisk) CID() string { +func (fake *FakeOrphanDisk) CID() string { fake.cIDMutex.Lock() fake.cIDArgsForCall = append(fake.cIDArgsForCall, struct{}{}) fake.recordInvocation("CID", []interface{}{}) @@ -67,20 +67,20 @@ func (fake *FakeOrphanedDisk) CID() string { } } -func (fake *FakeOrphanedDisk) CIDCallCount() int { +func (fake *FakeOrphanDisk) CIDCallCount() int { fake.cIDMutex.RLock() defer fake.cIDMutex.RUnlock() return len(fake.cIDArgsForCall) } -func (fake *FakeOrphanedDisk) CIDReturns(result1 string) { +func (fake *FakeOrphanDisk) CIDReturns(result1 string) { fake.CIDStub = nil fake.cIDReturns = struct { result1 string }{result1} } -func (fake *FakeOrphanedDisk) Size() uint64 { +func (fake *FakeOrphanDisk) Size() uint64 { fake.sizeMutex.Lock() fake.sizeArgsForCall = append(fake.sizeArgsForCall, struct{}{}) fake.recordInvocation("Size", []interface{}{}) @@ -92,20 +92,20 @@ func (fake *FakeOrphanedDisk) Size() uint64 { } } -func (fake *FakeOrphanedDisk) SizeCallCount() int { +func (fake *FakeOrphanDisk) SizeCallCount() int { fake.sizeMutex.RLock() defer fake.sizeMutex.RUnlock() return len(fake.sizeArgsForCall) } -func (fake *FakeOrphanedDisk) SizeReturns(result1 uint64) { +func (fake *FakeOrphanDisk) SizeReturns(result1 uint64) { fake.SizeStub = nil fake.sizeReturns = struct { result1 uint64 }{result1} } -func (fake *FakeOrphanedDisk) Deployment() director.Deployment { +func (fake *FakeOrphanDisk) Deployment() director.Deployment { fake.deploymentMutex.Lock() fake.deploymentArgsForCall = append(fake.deploymentArgsForCall, struct{}{}) fake.recordInvocation("Deployment", []interface{}{}) @@ -117,20 +117,20 @@ func (fake *FakeOrphanedDisk) Deployment() director.Deployment { } } -func (fake *FakeOrphanedDisk) DeploymentCallCount() int { +func (fake *FakeOrphanDisk) DeploymentCallCount() int { fake.deploymentMutex.RLock() defer fake.deploymentMutex.RUnlock() return len(fake.deploymentArgsForCall) } -func (fake *FakeOrphanedDisk) DeploymentReturns(result1 director.Deployment) { +func (fake *FakeOrphanDisk) DeploymentReturns(result1 director.Deployment) { fake.DeploymentStub = nil fake.deploymentReturns = struct { result1 director.Deployment }{result1} } -func (fake *FakeOrphanedDisk) InstanceName() string { +func (fake *FakeOrphanDisk) InstanceName() string { fake.instanceNameMutex.Lock() fake.instanceNameArgsForCall = append(fake.instanceNameArgsForCall, struct{}{}) fake.recordInvocation("InstanceName", []interface{}{}) @@ -142,20 +142,20 @@ func (fake *FakeOrphanedDisk) InstanceName() string { } } -func (fake *FakeOrphanedDisk) InstanceNameCallCount() int { +func (fake *FakeOrphanDisk) InstanceNameCallCount() int { fake.instanceNameMutex.RLock() defer fake.instanceNameMutex.RUnlock() return len(fake.instanceNameArgsForCall) } -func (fake *FakeOrphanedDisk) InstanceNameReturns(result1 string) { +func (fake *FakeOrphanDisk) InstanceNameReturns(result1 string) { fake.InstanceNameStub = nil fake.instanceNameReturns = struct { result1 string }{result1} } -func (fake *FakeOrphanedDisk) AZName() string { +func (fake *FakeOrphanDisk) AZName() string { fake.aZNameMutex.Lock() fake.aZNameArgsForCall = append(fake.aZNameArgsForCall, struct{}{}) fake.recordInvocation("AZName", []interface{}{}) @@ -167,20 +167,20 @@ func (fake *FakeOrphanedDisk) AZName() string { } } -func (fake *FakeOrphanedDisk) AZNameCallCount() int { +func (fake *FakeOrphanDisk) AZNameCallCount() int { fake.aZNameMutex.RLock() defer fake.aZNameMutex.RUnlock() return len(fake.aZNameArgsForCall) } -func (fake *FakeOrphanedDisk) AZNameReturns(result1 string) { +func (fake *FakeOrphanDisk) AZNameReturns(result1 string) { fake.AZNameStub = nil fake.aZNameReturns = struct { result1 string }{result1} } -func (fake *FakeOrphanedDisk) OrphanedAt() time.Time { +func (fake *FakeOrphanDisk) OrphanedAt() time.Time { fake.orphanedAtMutex.Lock() fake.orphanedAtArgsForCall = append(fake.orphanedAtArgsForCall, struct{}{}) fake.recordInvocation("OrphanedAt", []interface{}{}) @@ -192,20 +192,20 @@ func (fake *FakeOrphanedDisk) OrphanedAt() time.Time { } } -func (fake *FakeOrphanedDisk) OrphanedAtCallCount() int { +func (fake *FakeOrphanDisk) OrphanedAtCallCount() int { fake.orphanedAtMutex.RLock() defer fake.orphanedAtMutex.RUnlock() return len(fake.orphanedAtArgsForCall) } -func (fake *FakeOrphanedDisk) OrphanedAtReturns(result1 time.Time) { +func (fake *FakeOrphanDisk) OrphanedAtReturns(result1 time.Time) { fake.OrphanedAtStub = nil fake.orphanedAtReturns = struct { result1 time.Time }{result1} } -func (fake *FakeOrphanedDisk) Delete() error { +func (fake *FakeOrphanDisk) Delete() error { fake.deleteMutex.Lock() fake.deleteArgsForCall = append(fake.deleteArgsForCall, struct{}{}) fake.recordInvocation("Delete", []interface{}{}) @@ -217,20 +217,20 @@ func (fake *FakeOrphanedDisk) Delete() error { } } -func (fake *FakeOrphanedDisk) DeleteCallCount() int { +func (fake *FakeOrphanDisk) DeleteCallCount() int { fake.deleteMutex.RLock() defer fake.deleteMutex.RUnlock() return len(fake.deleteArgsForCall) } -func (fake *FakeOrphanedDisk) DeleteReturns(result1 error) { +func (fake *FakeOrphanDisk) DeleteReturns(result1 error) { fake.DeleteStub = nil fake.deleteReturns = struct { result1 error }{result1} } -func (fake *FakeOrphanedDisk) Invocations() map[string][][]interface{} { +func (fake *FakeOrphanDisk) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.cIDMutex.RLock() @@ -250,7 +250,7 @@ func (fake *FakeOrphanedDisk) Invocations() map[string][][]interface{} { return fake.invocations } -func (fake *FakeOrphanedDisk) recordInvocation(key string, args []interface{}) { +func (fake *FakeOrphanDisk) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { @@ -262,4 +262,4 @@ func (fake *FakeOrphanedDisk) recordInvocation(key string, args []interface{}) { fake.invocations[key] = append(fake.invocations[key], args) } -var _ director.OrphanedDisk = new(FakeOrphanedDisk) +var _ director.OrphanDisk = new(FakeOrphanDisk) diff --git a/director/interfaces.go b/director/interfaces.go index 734b8df3e..269b1023b 100644 --- a/director/interfaces.go +++ b/director/interfaces.go @@ -53,9 +53,9 @@ type Director interface { LatestRuntimeConfig(name string) (RuntimeConfig, error) UpdateRuntimeConfig(name string, manifest []byte) error - FindOrphanedDisk(string) (OrphanedDisk, error) - OrphanedDisks() ([]OrphanedDisk, error) - Orphan(string) error + FindOrphanDisk(string) (OrphanDisk, error) + OrphanDisks() ([]OrphanDisk, error) + OrphanDisk(string) error EnableResurrection(bool) error CleanUp(bool) error @@ -253,9 +253,9 @@ type TaskReporter interface { TaskOutputChunk(int, []byte) } -//go:generate counterfeiter . OrphanedDisk +//go:generate counterfeiter . OrphanDisk -type OrphanedDisk interface { +type OrphanDisk interface { CID() string Size() uint64 diff --git a/director/orphaned_disks.go b/director/orphan_disks.go similarity index 59% rename from director/orphaned_disks.go rename to director/orphan_disks.go index 34fa3534b..7d7de3ed2 100644 --- a/director/orphaned_disks.go +++ b/director/orphan_disks.go @@ -7,7 +7,7 @@ import ( bosherr "github.com/cloudfoundry/bosh-utils/errors" ) -type OrphanedDiskImpl struct { +type OrphanDiskImpl struct { client Client cid string @@ -20,22 +20,22 @@ type OrphanedDiskImpl struct { orphanedAt time.Time } -func (d OrphanedDiskImpl) CID() string { return d.cid } -func (d OrphanedDiskImpl) Size() uint64 { return d.size } +func (d OrphanDiskImpl) CID() string { return d.cid } +func (d OrphanDiskImpl) Size() uint64 { return d.size } -func (d OrphanedDiskImpl) Deployment() Deployment { +func (d OrphanDiskImpl) Deployment() Deployment { return &DeploymentImpl{client: d.client, name: d.deploymentName} } -func (d OrphanedDiskImpl) InstanceName() string { return d.instanceName } -func (d OrphanedDiskImpl) AZName() string { return d.azName } +func (d OrphanDiskImpl) InstanceName() string { return d.instanceName } +func (d OrphanDiskImpl) AZName() string { return d.azName } -func (d OrphanedDiskImpl) OrphanedAt() time.Time { return d.orphanedAt } +func (d OrphanDiskImpl) OrphanedAt() time.Time { return d.orphanedAt } -func (d OrphanedDiskImpl) Delete() error { - err := d.client.DeleteOrphanedDisk(d.cid) +func (d OrphanDiskImpl) Delete() error { + err := d.client.DeleteOrphanDisk(d.cid) if err != nil { - resps, listErr := d.client.OrphanedDisks() + resps, listErr := d.client.OrphanDisks() if listErr != nil { return err } @@ -50,30 +50,11 @@ func (d OrphanedDiskImpl) Delete() error { return nil } -func (d DirectorImpl) Orphan(cid string) error { - err := d.client.OrphanDisk(cid) - if err != nil { - resps, listErr := d.client.OrphanedDisks() - if listErr != nil { - return err - } - - found := false - for _, resp := range resps { - if resp.CID == cid { - found = true - break - } - } - if found == false { - return err - } - } - - return nil +func (d DirectorImpl) OrphanDisk(cid string) error { + return d.client.OrphanDisk(cid) } -type OrphanedDiskResp struct { +type OrphanDiskResp struct { CID string `json:"disk_cid"` Size uint64 @@ -84,14 +65,14 @@ type OrphanedDiskResp struct { OrphanedAt string `json:"orphaned_at"` // e.g. "2016-01-09 06:23:25 +0000" } -func (d DirectorImpl) FindOrphanedDisk(cid string) (OrphanedDisk, error) { - return OrphanedDiskImpl{client: d.client, cid: cid}, nil +func (d DirectorImpl) FindOrphanDisk(cid string) (OrphanDisk, error) { + return OrphanDiskImpl{client: d.client, cid: cid}, nil } -func (d DirectorImpl) OrphanedDisks() ([]OrphanedDisk, error) { - var disks []OrphanedDisk +func (d DirectorImpl) OrphanDisks() ([]OrphanDisk, error) { + var disks []OrphanDisk - resps, err := d.client.OrphanedDisks() + resps, err := d.client.OrphanDisks() if err != nil { return disks, err } @@ -102,7 +83,7 @@ func (d DirectorImpl) OrphanedDisks() ([]OrphanedDisk, error) { return disks, bosherr.WrapErrorf(err, "Converting orphaned at '%s' to time", r.OrphanedAt) } - disk := OrphanedDiskImpl{ + disk := OrphanDiskImpl{ client: d.client, cid: r.CID, @@ -121,8 +102,8 @@ func (d DirectorImpl) OrphanedDisks() ([]OrphanedDisk, error) { return disks, nil } -func (c Client) OrphanedDisks() ([]OrphanedDiskResp, error) { - var disks []OrphanedDiskResp +func (c Client) OrphanDisks() ([]OrphanDiskResp, error) { + var disks []OrphanDiskResp err := c.clientRequest.Get("/disks", &disks) if err != nil { @@ -132,7 +113,7 @@ func (c Client) OrphanedDisks() ([]OrphanedDiskResp, error) { return disks, nil } -func (c Client) DeleteOrphanedDisk(cid string) error { +func (c Client) DeleteOrphanDisk(cid string) error { if len(cid) == 0 { return bosherr.Error("Expected non-empty orphaned disk CID") } diff --git a/director/orphaned_disks_test.go b/director/orphan_disks_test.go similarity index 74% rename from director/orphaned_disks_test.go rename to director/orphan_disks_test.go index aca64ac07..0e9b3be16 100644 --- a/director/orphaned_disks_test.go +++ b/director/orphan_disks_test.go @@ -25,7 +25,7 @@ var _ = Describe("Director", func() { server.Close() }) - Describe("OrphanedDisks", func() { + Describe("OrphanDisks", func() { It("returns orphaned disks", func() { server.AppendHandlers( ghttp.CombineHandlers( @@ -62,7 +62,7 @@ var _ = Describe("Director", func() { dep2, err := director.FindDeployment("dep2") Expect(err).ToNot(HaveOccurred()) - disks, err := director.OrphanedDisks() + disks, err := director.OrphanDisks() Expect(err).ToNot(HaveOccurred()) Expect(disks).To(HaveLen(2)) @@ -84,7 +84,7 @@ var _ = Describe("Director", func() { It("returns error if response is non-200", func() { AppendBadRequest(ghttp.VerifyRequest("GET", "/disks"), server) - _, err := director.OrphanedDisks() + _, err := director.OrphanDisks() Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring( "Finding orphaned disks: Director responded with non-successful status code")) @@ -98,7 +98,7 @@ var _ = Describe("Director", func() { ), ) - _, err := director.OrphanedDisks() + _, err := director.OrphanDisks() Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring( "Finding orphaned disks: Unmarshaling Director response")) @@ -106,10 +106,10 @@ var _ = Describe("Director", func() { }) }) -var _ = Describe("OrphanedDisk", func() { +var _ = Describe("OrphanDisk", func() { var ( director Director - disk OrphanedDisk + disk OrphanDisk server *ghttp.Server ) @@ -118,7 +118,7 @@ var _ = Describe("OrphanedDisk", func() { var err error - disk, err = director.FindOrphanedDisk("cid") + disk, err = director.FindOrphanDisk("cid") Expect(err).ToNot(HaveOccurred()) }) @@ -216,7 +216,7 @@ var _ = Describe("OrphanedDisk", func() { }) }) - Describe("Orphan", func() { + Describe("OrphanDisk", func() { It("orphans disk", func() { ConfigureTaskResult( ghttp.CombineHandlers( @@ -227,77 +227,27 @@ var _ = Describe("OrphanedDisk", func() { server, ) - Expect(director.Orphan("cid")).ToNot(HaveOccurred()) + Expect(director.OrphanDisk("cid")).ToNot(HaveOccurred()) }) - It("succeeds even if error occurrs if orphaned disk exists", func() { - server.AppendHandlers( - ghttp.CombineHandlers( - ghttp.VerifyRequest("DELETE", "/disks/cid", "orphan=true"), - ghttp.RespondWith(http.StatusBadRequest, ``), - ), - ghttp.CombineHandlers( - ghttp.VerifyRequest("GET", "/disks"), - ghttp.VerifyBasicAuth("username", "password"), - ghttp.RespondWith(http.StatusOK, `[ - { "disk_cid": "cid", "orphaned_at": "2016-01-09 06:23:25 +0000" } -]`), - ), - ) - - Expect(director.Orphan("cid")).ToNot(HaveOccurred()) - }) - - It("returns orphan error if listing disks fails", func() { - server.AppendHandlers( - ghttp.CombineHandlers( - ghttp.VerifyRequest("DELETE", "/disks/cid", "orphan=true"), - ghttp.RespondWith(http.StatusBadRequest, ``), - ), - ghttp.CombineHandlers( - ghttp.VerifyRequest("GET", "/disks"), - ghttp.VerifyBasicAuth("username", "password"), - ghttp.RespondWith(http.StatusOK, ``), - ), - ) - - err := director.Orphan("cid") - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring( - "Orphaning disk 'cid': Director responded with non-successful status code")) - }) - - It("returns error if response is non-200 and orphaned disk does not exist", func() { + It("returns error if response is non-200", func() { AppendBadRequest(ghttp.VerifyRequest("DELETE", "/disks/cid", "orphan=true"), server) - server.AppendHandlers( - ghttp.CombineHandlers( - ghttp.VerifyRequest("GET", "/disks"), - ghttp.VerifyBasicAuth("username", "password"), - ghttp.RespondWith(http.StatusOK, `[]`), - ), - ) - - err := director.Orphan("cid") + err := director.OrphanDisk("cid") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring( "Orphaning disk 'cid': Director responded with non-successful status code")) }) - It("returns error if response cannot be unmarshalled and orphaned disk does not exist", func() { + It("returns error if response cannot be unmarshalled", func() { server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("DELETE", "/disks/cid", "orphan=true"), ghttp.RespondWith(http.StatusOK, ``), ), - ghttp.CombineHandlers( - ghttp.VerifyRequest("GET", "/disks"), - ghttp.VerifyBasicAuth("username", "password"), - ghttp.RespondWith(http.StatusOK, `[]`), - ), ) - err := director.Orphan("cid") + err := director.OrphanDisk("cid") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring( "Orphaning disk 'cid': Unmarshaling Director response"))