Skip to content

Commit

Permalink
fix instances cmd and make sure all fakes are gend
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvman committed Sep 1, 2016
1 parent ff34531 commit d9bbeea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cmd/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var _ = Describe("InstancesCmd", func() {
},
}

deployment.VMInfosReturns(infos, nil)
deployment.InstanceInfosReturns(infos, nil)
})

It("lists instances for the deployment", func() {
Expand Down Expand Up @@ -729,7 +729,7 @@ var _ = Describe("InstancesCmd", func() {
})

It("returns error if instances cannot be retrieved", func() {
deployment.VMInfosReturns(nil, errors.New("fake-err"))
deployment.InstanceInfosReturns(nil, errors.New("fake-err"))

err := act()
Expect(err).To(HaveOccurred())
Expand Down
36 changes: 32 additions & 4 deletions director/fakes/fake_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ type FakeDeployment struct {
result1 []director.VMInfo
result2 error
}
InstanceInfosStub func() ([]director.VMInfo, error)
instanceInfosMutex sync.RWMutex
instanceInfosArgsForCall []struct{}
instanceInfosReturns struct {
result1 []director.VMInfo
result2 error
}
ErrandsStub func() ([]director.Errand, error)
errandsMutex sync.RWMutex
errandsArgsForCall []struct{}
Expand Down Expand Up @@ -437,10 +444,6 @@ func (fake *FakeDeployment) VMInfos() ([]director.VMInfo, error) {
}
}

func (fake *FakeDeployment) InstanceInfos() ([]director.VMInfo, error) {
return fake.VMInfos()
}

func (fake *FakeDeployment) VMInfosCallCount() int {
fake.vMInfosMutex.RLock()
defer fake.vMInfosMutex.RUnlock()
Expand All @@ -455,6 +458,31 @@ func (fake *FakeDeployment) VMInfosReturns(result1 []director.VMInfo, result2 er
}{result1, result2}
}

func (fake *FakeDeployment) InstanceInfos() ([]director.VMInfo, error) {
fake.instanceInfosMutex.Lock()
fake.instanceInfosArgsForCall = append(fake.instanceInfosArgsForCall, struct{}{})
fake.instanceInfosMutex.Unlock()
if fake.InstanceInfosStub != nil {
return fake.InstanceInfosStub()
} else {
return fake.instanceInfosReturns.result1, fake.instanceInfosReturns.result2
}
}

func (fake *FakeDeployment) InstanceInfosCallCount() int {
fake.instanceInfosMutex.RLock()
defer fake.instanceInfosMutex.RUnlock()
return len(fake.instanceInfosArgsForCall)
}

func (fake *FakeDeployment) InstanceInfosReturns(result1 []director.VMInfo, result2 error) {
fake.InstanceInfosStub = nil
fake.instanceInfosReturns = struct {
result1 []director.VMInfo
result2 error
}{result1, result2}
}

func (fake *FakeDeployment) Errands() ([]director.Errand, error) {
fake.errandsMutex.Lock()
fake.errandsArgsForCall = append(fake.errandsArgsForCall, struct{}{})
Expand Down
26 changes: 0 additions & 26 deletions releasedir/index/fakes/fake_index_blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ type FakeIndexBlobs struct {
result2 string
result3 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}

func (fake *FakeIndexBlobs) Get(name string, blobID string, sha1 string) (string, error) {
Expand All @@ -41,7 +39,6 @@ func (fake *FakeIndexBlobs) Get(name string, blobID string, sha1 string) (string
blobID string
sha1 string
}{name, blobID, sha1})
fake.recordInvocation("Get", []interface{}{name, blobID, sha1})
fake.getMutex.Unlock()
if fake.GetStub != nil {
return fake.GetStub(name, blobID, sha1)
Expand Down Expand Up @@ -76,7 +73,6 @@ func (fake *FakeIndexBlobs) Add(path string, sha1 string) (string, string, error
path string
sha1 string
}{path, sha1})
fake.recordInvocation("Add", []interface{}{path, sha1})
fake.addMutex.Unlock()
if fake.AddStub != nil {
return fake.AddStub(path, sha1)
Expand Down Expand Up @@ -106,26 +102,4 @@ func (fake *FakeIndexBlobs) AddReturns(result1 string, result2 string, result3 e
}{result1, result2, result3}
}

func (fake *FakeIndexBlobs) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.getMutex.RLock()
defer fake.getMutex.RUnlock()
fake.addMutex.RLock()
defer fake.addMutex.RUnlock()
return fake.invocations
}

func (fake *FakeIndexBlobs) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}

var _ index.IndexBlobs = new(FakeIndexBlobs)

0 comments on commit d9bbeea

Please sign in to comment.