github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/api/fakes/fake_service_broker_repo.go (about)

     1  package fakes
     2  
     3  import (
     4  	"github.com/cloudfoundry/cli/cf/errors"
     5  	"github.com/cloudfoundry/cli/cf/models"
     6  )
     7  
     8  type FakeServiceBrokerRepo struct {
     9  	FindByNameName          string
    10  	FindByNameServiceBroker models.ServiceBroker
    11  	FindByNameNotFound      bool
    12  
    13  	FindByGuidGuid          string
    14  	FindByGuidServiceBroker models.ServiceBroker
    15  	FindByGuidNotFound      bool
    16  
    17  	CreateName     string
    18  	CreateUrl      string
    19  	CreateUsername string
    20  	CreatePassword string
    21  
    22  	UpdatedServiceBroker     models.ServiceBroker
    23  	RenamedServiceBrokerGuid string
    24  	RenamedServiceBrokerName string
    25  	DeletedServiceBrokerGuid string
    26  
    27  	ServiceBrokers []models.ServiceBroker
    28  	ListErr        bool
    29  }
    30  
    31  func (repo *FakeServiceBrokerRepo) FindByName(name string) (serviceBroker models.ServiceBroker, apiErr error) {
    32  	repo.FindByNameName = name
    33  	serviceBroker = repo.FindByNameServiceBroker
    34  
    35  	if repo.FindByNameNotFound {
    36  		apiErr = errors.NewModelNotFoundError("Service Broker", name)
    37  	}
    38  
    39  	return
    40  }
    41  
    42  func (repo *FakeServiceBrokerRepo) FindByGuid(guid string) (serviceBroker models.ServiceBroker, apiErr error) {
    43  	repo.FindByGuidGuid = guid
    44  	serviceBroker = repo.FindByGuidServiceBroker
    45  
    46  	if repo.FindByGuidNotFound {
    47  		apiErr = errors.NewModelNotFoundError("Service Broker", guid)
    48  	}
    49  
    50  	return
    51  }
    52  
    53  func (repo *FakeServiceBrokerRepo) ListServiceBrokers(callback func(broker models.ServiceBroker) bool) error {
    54  	for _, broker := range repo.ServiceBrokers {
    55  		if !callback(broker) {
    56  			break
    57  		}
    58  	}
    59  
    60  	if repo.ListErr {
    61  		return errors.New("Error finding service brokers")
    62  	} else {
    63  		return nil
    64  	}
    65  }
    66  
    67  func (repo *FakeServiceBrokerRepo) Create(name, url, username, password string) (apiErr error) {
    68  	repo.CreateName = name
    69  	repo.CreateUrl = url
    70  	repo.CreateUsername = username
    71  	repo.CreatePassword = password
    72  	return
    73  }
    74  
    75  func (repo *FakeServiceBrokerRepo) Update(serviceBroker models.ServiceBroker) (apiErr error) {
    76  	repo.UpdatedServiceBroker = serviceBroker
    77  	return
    78  }
    79  
    80  func (repo *FakeServiceBrokerRepo) Rename(guid, name string) (apiErr error) {
    81  	repo.RenamedServiceBrokerGuid = guid
    82  	repo.RenamedServiceBrokerName = name
    83  	return
    84  }
    85  
    86  func (repo *FakeServiceBrokerRepo) Delete(guid string) (apiErr error) {
    87  	repo.DeletedServiceBrokerGuid = guid
    88  	return
    89  }