forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_buildpack_repo.go
83 lines (65 loc) · 2.17 KB
/
fake_buildpack_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package api
import (
"cf"
"cf/net"
)
type FakeBuildpackRepository struct {
Buildpacks []cf.Buildpack
FindByNameNotFound bool
FindByNameName string
FindByNameBuildpack cf.Buildpack
FindByNameApiResponse net.ApiResponse
CreateBuildpackExists bool
CreateBuildpack cf.Buildpack
CreateApiResponse net.ApiResponse
DeleteBuildpackGuid string
DeleteApiResponse net.ApiResponse
UpdateBuildpack cf.Buildpack
}
func (repo *FakeBuildpackRepository) ListBuildpacks(stop chan bool) (buildpacksChan chan []cf.Buildpack, statusChan chan net.ApiResponse) {
buildpacksChan = make(chan []cf.Buildpack, 4)
statusChan = make(chan net.ApiResponse, 1)
go func() {
buildpackCount := len(repo.Buildpacks)
for i := 0; i < buildpackCount; i += 2 {
select {
case <-stop:
break
default:
if buildpackCount-i > 1 {
buildpacksChan <- repo.Buildpacks[i : i+2]
} else {
buildpacksChan <- repo.Buildpacks[i:]
}
}
}
close(buildpacksChan)
close(statusChan)
cf.WaitForClose(stop)
}()
return
}
func (repo *FakeBuildpackRepository) FindByName(name string) (buildpack cf.Buildpack, apiResponse net.ApiResponse) {
repo.FindByNameName = name
buildpack = repo.FindByNameBuildpack
if repo.FindByNameNotFound {
apiResponse = net.NewNotFoundApiResponse("Buildpack %s not found", name)
}
return
}
func (repo *FakeBuildpackRepository) Create(name string, position *int, enabled *bool, locked *bool) (createdBuildpack cf.Buildpack, apiResponse net.ApiResponse) {
if repo.CreateBuildpackExists {
return repo.CreateBuildpack, net.NewApiResponse("Buildpack already exists", cf.BUILDPACK_EXISTS, 400)
}
repo.CreateBuildpack = cf.Buildpack{BasicFields: cf.BasicFields{Name: name}, Position: position, Enabled: enabled, Locked: locked}
return repo.CreateBuildpack, repo.CreateApiResponse
}
func (repo *FakeBuildpackRepository) Delete(buildpackGuid string) (apiResponse net.ApiResponse) {
repo.DeleteBuildpackGuid = buildpackGuid
apiResponse = repo.DeleteApiResponse
return
}
func (repo *FakeBuildpackRepository) Update(buildpack cf.Buildpack) (updatedBuildpack cf.Buildpack, apiResponse net.ApiResponse) {
repo.UpdateBuildpack = buildpack
return
}