github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/api/apifakes/old_fake_buildpack_repo.go (about)

     1  package apifakes
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/errors"
     5  	"code.cloudfoundry.org/cli/cf/models"
     6  )
     7  
     8  type OldFakeBuildpackRepository struct {
     9  	Buildpacks []models.Buildpack
    10  
    11  	FindByNameNotFound    bool
    12  	FindByNameName        string
    13  	FindByNameBuildpack   models.Buildpack
    14  	FindByNameAPIResponse error
    15  
    16  	CreateBuildpackExists bool
    17  	CreateBuildpack       models.Buildpack
    18  	CreateAPIResponse     error
    19  
    20  	DeleteBuildpackGUID string
    21  	DeleteAPIResponse   error
    22  
    23  	UpdateBuildpackArgs struct {
    24  		Buildpack models.Buildpack
    25  	}
    26  
    27  	UpdateBuildpackReturns struct {
    28  		Error error
    29  	}
    30  }
    31  
    32  func (repo *OldFakeBuildpackRepository) ListBuildpacks(cb func(models.Buildpack) bool) error {
    33  	for _, b := range repo.Buildpacks {
    34  		cb(b)
    35  	}
    36  	return nil
    37  }
    38  
    39  func (repo *OldFakeBuildpackRepository) FindByName(name string) (buildpack models.Buildpack, apiErr error) {
    40  	repo.FindByNameName = name
    41  	buildpack = repo.FindByNameBuildpack
    42  
    43  	if repo.FindByNameNotFound {
    44  		apiErr = errors.NewModelNotFoundError("Buildpack", name)
    45  	}
    46  
    47  	return
    48  }
    49  
    50  func (repo *OldFakeBuildpackRepository) Create(name string, position *int, enabled *bool, locked *bool) (createdBuildpack models.Buildpack, apiErr error) {
    51  	if repo.CreateBuildpackExists {
    52  		return repo.CreateBuildpack, errors.NewHTTPError(400, errors.BuildpackNameTaken, "Buildpack already exists")
    53  	}
    54  
    55  	repo.CreateBuildpack = models.Buildpack{Name: name, Position: position, Enabled: enabled, Locked: locked}
    56  	return repo.CreateBuildpack, repo.CreateAPIResponse
    57  }
    58  
    59  func (repo *OldFakeBuildpackRepository) Delete(buildpackGUID string) (apiErr error) {
    60  	repo.DeleteBuildpackGUID = buildpackGUID
    61  	apiErr = repo.DeleteAPIResponse
    62  	return
    63  }
    64  
    65  func (repo *OldFakeBuildpackRepository) Update(buildpack models.Buildpack) (updatedBuildpack models.Buildpack, apiErr error) {
    66  	repo.UpdateBuildpackArgs.Buildpack = buildpack
    67  	apiErr = repo.UpdateBuildpackReturns.Error
    68  	return
    69  }