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

     1  package fakes
     2  
     3  import (
     4  	"github.com/cloudfoundry/cli/cf/api/resources"
     5  	"github.com/cloudfoundry/cli/cf/errors"
     6  	"github.com/cloudfoundry/cli/cf/models"
     7  	"github.com/cloudfoundry/cli/generic"
     8  )
     9  
    10  type FakeServiceRepo struct {
    11  	GetServiceOfferingByGuidReturns struct {
    12  		ServiceOffering models.ServiceOffering
    13  		Error           error
    14  	}
    15  
    16  	GetAllServiceOfferingsReturns struct {
    17  		ServiceOfferings []models.ServiceOffering
    18  		Error            error
    19  	}
    20  
    21  	GetServiceOfferingsForSpaceReturns struct {
    22  		ServiceOfferings []models.ServiceOffering
    23  		Error            error
    24  	}
    25  	GetServiceOfferingsForSpaceArgs struct {
    26  		SpaceGuid string
    27  	}
    28  
    29  	FindServiceOfferingsForSpaceByLabelArgs struct {
    30  		SpaceGuid string
    31  		Name      string
    32  	}
    33  
    34  	FindServiceOfferingsForSpaceByLabelReturns struct {
    35  		ServiceOfferings models.ServiceOfferings
    36  		Error            error
    37  	}
    38  
    39  	CreateServiceInstanceArgs struct {
    40  		Name     string
    41  		PlanGuid string
    42  	}
    43  	CreateServiceInstanceReturns struct {
    44  		Error error
    45  	}
    46  
    47  	UpdateServiceInstanceArgs struct {
    48  		InstanceGuid string
    49  		PlanGuid     string
    50  	}
    51  
    52  	UpdateServiceInstanceReturnsErr bool
    53  
    54  	FindInstanceByNameName            string
    55  	FindInstanceByNameServiceInstance models.ServiceInstance
    56  	FindInstanceByNameErr             bool
    57  	FindInstanceByNameNotFound        bool
    58  
    59  	FindInstanceByNameMap generic.Map
    60  
    61  	DeleteServiceServiceInstance models.ServiceInstance
    62  
    63  	RenameServiceServiceInstance models.ServiceInstance
    64  	RenameServiceNewName         string
    65  
    66  	PurgedServiceOffering           models.ServiceOffering
    67  	PurgeServiceOfferingCalled      bool
    68  	PurgeServiceOfferingApiResponse error
    69  
    70  	FindServiceOfferingByLabelAndProviderName            string
    71  	FindServiceOfferingByLabelAndProviderProvider        string
    72  	FindServiceOfferingByLabelAndProviderServiceOffering models.ServiceOffering
    73  	FindServiceOfferingByLabelAndProviderApiResponse     error
    74  	FindServiceOfferingByLabelAndProviderCalled          bool
    75  
    76  	FindServiceOfferingsByLabelName             string
    77  	FindServiceOfferingsByLabelServiceOfferings models.ServiceOfferings
    78  	FindServiceOfferingsByLabelApiResponse      error
    79  	FindServiceOfferingsByLabelCalled           bool
    80  
    81  	ListServicesFromBrokerReturns map[string][]models.ServiceOffering
    82  	ListServicesFromBrokerErr     error
    83  
    84  	V1ServicePlanDescription                resources.ServicePlanDescription
    85  	V2ServicePlanDescription                resources.ServicePlanDescription
    86  	FindServicePlanByDescriptionArguments   []resources.ServicePlanDescription
    87  	FindServicePlanByDescriptionResultGuids []string
    88  	FindServicePlanByDescriptionResponses   []error
    89  	findServicePlanByDescriptionCallCount   int
    90  
    91  	ServiceInstanceCountForServicePlan int
    92  	ServiceInstanceCountApiResponse    error
    93  
    94  	V1GuidToMigrate                           string
    95  	V2GuidToMigrate                           string
    96  	MigrateServicePlanFromV1ToV2Called        bool
    97  	MigrateServicePlanFromV1ToV2ReturnedCount int
    98  	MigrateServicePlanFromV1ToV2Response      error
    99  }
   100  
   101  func (repo *FakeServiceRepo) GetServiceOfferingByGuid(guid string) (models.ServiceOffering, error) {
   102  	return repo.GetServiceOfferingByGuidReturns.ServiceOffering, repo.GetServiceOfferingByGuidReturns.Error
   103  }
   104  
   105  func (repo *FakeServiceRepo) GetAllServiceOfferings() (models.ServiceOfferings, error) {
   106  	return repo.GetAllServiceOfferingsReturns.ServiceOfferings, repo.GetAllServiceOfferingsReturns.Error
   107  }
   108  
   109  func (repo *FakeServiceRepo) GetServiceOfferingsForSpace(spaceGuid string) (models.ServiceOfferings, error) {
   110  	repo.GetServiceOfferingsForSpaceArgs.SpaceGuid = spaceGuid
   111  	return repo.GetServiceOfferingsForSpaceReturns.ServiceOfferings, repo.GetServiceOfferingsForSpaceReturns.Error
   112  }
   113  
   114  func (repo *FakeServiceRepo) FindServiceOfferingsForSpaceByLabel(spaceGuid, name string) (models.ServiceOfferings, error) {
   115  	repo.FindServiceOfferingsForSpaceByLabelArgs.Name = name
   116  	repo.FindServiceOfferingsForSpaceByLabelArgs.SpaceGuid = spaceGuid
   117  	return repo.FindServiceOfferingsForSpaceByLabelReturns.ServiceOfferings, repo.FindServiceOfferingsForSpaceByLabelReturns.Error
   118  }
   119  
   120  func (repo *FakeServiceRepo) PurgeServiceOffering(offering models.ServiceOffering) (apiErr error) {
   121  	repo.PurgedServiceOffering = offering
   122  	repo.PurgeServiceOfferingCalled = true
   123  	return repo.PurgeServiceOfferingApiResponse
   124  }
   125  
   126  func (repo *FakeServiceRepo) FindServiceOfferingByLabelAndProvider(name, provider string) (offering models.ServiceOffering, apiErr error) {
   127  	repo.FindServiceOfferingByLabelAndProviderCalled = true
   128  	repo.FindServiceOfferingByLabelAndProviderName = name
   129  	repo.FindServiceOfferingByLabelAndProviderProvider = provider
   130  	apiErr = repo.FindServiceOfferingByLabelAndProviderApiResponse
   131  	offering = repo.FindServiceOfferingByLabelAndProviderServiceOffering
   132  	return
   133  }
   134  
   135  func (repo *FakeServiceRepo) FindServiceOfferingsByLabel(name string) (offerings models.ServiceOfferings, apiErr error) {
   136  	repo.FindServiceOfferingsByLabelCalled = true
   137  	repo.FindServiceOfferingsByLabelName = name
   138  	apiErr = repo.FindServiceOfferingsByLabelApiResponse
   139  	offerings = repo.FindServiceOfferingsByLabelServiceOfferings
   140  	return
   141  }
   142  
   143  func (repo *FakeServiceRepo) CreateServiceInstance(name, planGuid string) (apiErr error) {
   144  	repo.CreateServiceInstanceArgs.Name = name
   145  	repo.CreateServiceInstanceArgs.PlanGuid = planGuid
   146  
   147  	return repo.CreateServiceInstanceReturns.Error
   148  }
   149  
   150  func (repo *FakeServiceRepo) UpdateServiceInstance(instanceGuid, planGuid string) (apiErr error) {
   151  
   152  	if repo.UpdateServiceInstanceReturnsErr {
   153  		apiErr = errors.New("Error updating service instance")
   154  	} else {
   155  		repo.UpdateServiceInstanceArgs.InstanceGuid = instanceGuid
   156  		repo.UpdateServiceInstanceArgs.PlanGuid = planGuid
   157  	}
   158  
   159  	return
   160  }
   161  
   162  func (repo *FakeServiceRepo) FindInstanceByName(name string) (instance models.ServiceInstance, apiErr error) {
   163  	repo.FindInstanceByNameName = name
   164  
   165  	if repo.FindInstanceByNameMap != nil && repo.FindInstanceByNameMap.Has(name) {
   166  		instance = repo.FindInstanceByNameMap.Get(name).(models.ServiceInstance)
   167  	} else {
   168  		instance = repo.FindInstanceByNameServiceInstance
   169  	}
   170  
   171  	if repo.FindInstanceByNameErr {
   172  		apiErr = errors.New("Error finding instance")
   173  	}
   174  
   175  	if repo.FindInstanceByNameNotFound {
   176  		apiErr = errors.NewModelNotFoundError("Service instance", name)
   177  	}
   178  
   179  	return
   180  }
   181  
   182  func (repo *FakeServiceRepo) DeleteService(instance models.ServiceInstance) (apiErr error) {
   183  	repo.DeleteServiceServiceInstance = instance
   184  	return
   185  }
   186  
   187  func (repo *FakeServiceRepo) RenameService(instance models.ServiceInstance, newName string) (apiErr error) {
   188  	repo.RenameServiceServiceInstance = instance
   189  	repo.RenameServiceNewName = newName
   190  	return
   191  }
   192  
   193  func (repo *FakeServiceRepo) FindServicePlanByDescription(planDescription resources.ServicePlanDescription) (planGuid string, apiErr error) {
   194  
   195  	repo.FindServicePlanByDescriptionArguments =
   196  		append(repo.FindServicePlanByDescriptionArguments, planDescription)
   197  
   198  	if len(repo.FindServicePlanByDescriptionResultGuids) > repo.findServicePlanByDescriptionCallCount {
   199  		planGuid = repo.FindServicePlanByDescriptionResultGuids[repo.findServicePlanByDescriptionCallCount]
   200  	}
   201  	if len(repo.FindServicePlanByDescriptionResponses) > repo.findServicePlanByDescriptionCallCount {
   202  		apiErr = repo.FindServicePlanByDescriptionResponses[repo.findServicePlanByDescriptionCallCount]
   203  	}
   204  	repo.findServicePlanByDescriptionCallCount += 1
   205  	return
   206  }
   207  
   208  func (repo *FakeServiceRepo) ListServicesFromBroker(brokerGuid string) ([]models.ServiceOffering, error) {
   209  	if repo.ListServicesFromBrokerErr != nil {
   210  		return nil, repo.ListServicesFromBrokerErr
   211  	}
   212  
   213  	if repo.ListServicesFromBrokerReturns[brokerGuid] != nil {
   214  		return repo.ListServicesFromBrokerReturns[brokerGuid], nil
   215  	}
   216  
   217  	return []models.ServiceOffering{}, nil
   218  }
   219  
   220  func (repo *FakeServiceRepo) GetServiceInstanceCountForServicePlan(v1PlanGuid string) (count int, apiErr error) {
   221  	count = repo.ServiceInstanceCountForServicePlan
   222  	apiErr = repo.ServiceInstanceCountApiResponse
   223  	return
   224  }
   225  
   226  func (repo *FakeServiceRepo) MigrateServicePlanFromV1ToV2(v1PlanGuid, v2PlanGuid string) (changedCount int, apiErr error) {
   227  	repo.MigrateServicePlanFromV1ToV2Called = true
   228  	repo.V1GuidToMigrate = v1PlanGuid
   229  	repo.V2GuidToMigrate = v2PlanGuid
   230  	changedCount = repo.MigrateServicePlanFromV1ToV2ReturnedCount
   231  	apiErr = repo.MigrateServicePlanFromV1ToV2Response
   232  	return
   233  }