github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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  	FindByNameAmbiguous   bool
    16  
    17  	FindByNameAndStackNotFound  bool
    18  	FindByNameAndStackName      string
    19  	FindByNameAndStackStack     string
    20  	FindByNameAndStackBuildpack models.Buildpack
    21  
    22  	FindByNameWithNilStackNotFound  bool
    23  	FindByNameWithNilStackName      string
    24  	FindByNameWithNilStackBuildpack models.Buildpack
    25  
    26  	CreateBuildpackExists             bool
    27  	CreateBuildpackWithNilStackExists bool
    28  	CreateBuildpack                   models.Buildpack
    29  	CreateAPIResponse                 error
    30  
    31  	DeleteBuildpackGUID string
    32  	DeleteAPIResponse   error
    33  
    34  	UpdateBuildpackArgs struct {
    35  		Buildpack models.Buildpack
    36  	}
    37  
    38  	UpdateBuildpackReturns struct {
    39  		Error error
    40  	}
    41  }
    42  
    43  func (repo *OldFakeBuildpackRepository) ListBuildpacks(cb func(models.Buildpack) bool) error {
    44  	for _, b := range repo.Buildpacks {
    45  		cb(b)
    46  	}
    47  	return nil
    48  }
    49  
    50  func (repo *OldFakeBuildpackRepository) FindByName(name string) (buildpack models.Buildpack, apiErr error) {
    51  	repo.FindByNameName = name
    52  	buildpack = repo.FindByNameBuildpack
    53  
    54  	if repo.FindByNameNotFound {
    55  		apiErr = errors.NewModelNotFoundError("Buildpack", name)
    56  	} else if repo.FindByNameAmbiguous {
    57  		apiErr = errors.NewAmbiguousModelError("Buildpack", name)
    58  	}
    59  
    60  	return
    61  }
    62  
    63  func (repo *OldFakeBuildpackRepository) FindByNameAndStack(name, stack string) (buildpack models.Buildpack, apiErr error) {
    64  	repo.FindByNameAndStackName = name
    65  	repo.FindByNameAndStackStack = stack
    66  	buildpack = repo.FindByNameAndStackBuildpack
    67  
    68  	if repo.FindByNameAndStackNotFound {
    69  		apiErr = errors.NewModelNotFoundError("Buildpack", name)
    70  	}
    71  
    72  	return
    73  }
    74  
    75  func (repo *OldFakeBuildpackRepository) FindByNameWithNilStack(name string) (buildpack models.Buildpack, apiErr error) {
    76  	repo.FindByNameWithNilStackName = name
    77  	buildpack = repo.FindByNameWithNilStackBuildpack
    78  
    79  	if repo.FindByNameWithNilStackNotFound {
    80  		apiErr = errors.NewModelNotFoundError("Buildpack", name)
    81  	}
    82  
    83  	return
    84  }
    85  
    86  func (repo *OldFakeBuildpackRepository) Create(name string, position *int, enabled *bool, locked *bool) (createdBuildpack models.Buildpack, apiErr error) {
    87  	if repo.CreateBuildpackExists {
    88  		return repo.CreateBuildpack, errors.NewHTTPError(400, errors.BuildpackNameTaken, "Buildpack already exists")
    89  	} else if repo.CreateBuildpackWithNilStackExists {
    90  		return repo.CreateBuildpack, errors.NewHTTPError(400, errors.StackUnique, "stack unique")
    91  	}
    92  
    93  	repo.CreateBuildpack = models.Buildpack{Name: name, Position: position, Enabled: enabled, Locked: locked, GUID: "BUILDPACK-GUID-X"}
    94  	return repo.CreateBuildpack, repo.CreateAPIResponse
    95  }
    96  
    97  func (repo *OldFakeBuildpackRepository) Delete(buildpackGUID string) (apiErr error) {
    98  	repo.DeleteBuildpackGUID = buildpackGUID
    99  	apiErr = repo.DeleteAPIResponse
   100  	return
   101  }
   102  
   103  func (repo *OldFakeBuildpackRepository) Update(buildpack models.Buildpack) (updatedBuildpack models.Buildpack, apiErr error) {
   104  	repo.UpdateBuildpackArgs.Buildpack = buildpack
   105  	apiErr = repo.UpdateBuildpackReturns.Error
   106  	return
   107  }