forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_app_instances_repo.go
39 lines (30 loc) · 992 Bytes
/
fake_app_instances_repo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fakes
import (
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/models"
)
type FakeAppInstancesRepo struct {
GetInstancesAppGuid string
GetInstancesResponses [][]models.AppInstanceFields
GetInstancesErrorCodes []string
}
func (repo *FakeAppInstancesRepo) GetInstances(appGuid string) (instances []models.AppInstanceFields, apiErr error) {
repo.GetInstancesAppGuid = appGuid
if len(repo.GetInstancesResponses) > 0 {
instances = repo.GetInstancesResponses[0]
if len(repo.GetInstancesResponses) > 1 {
repo.GetInstancesResponses = repo.GetInstancesResponses[1:]
}
}
if len(repo.GetInstancesErrorCodes) > 0 {
errorCode := repo.GetInstancesErrorCodes[0]
// don't slice away the last one if this is all we have
if len(repo.GetInstancesErrorCodes) > 1 {
repo.GetInstancesErrorCodes = repo.GetInstancesErrorCodes[1:]
}
if errorCode != "" {
apiErr = errors.NewHttpError(400, errorCode, "Error staging app")
}
}
return
}