github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/api/apifakes/old_fake_service_plan_repo.go (about) 1 package apifakes 2 3 import ( 4 "sort" 5 "strings" 6 "sync" 7 8 "code.cloudfoundry.org/cli/cf/models" 9 ) 10 11 type OldFakeServicePlanRepo struct { 12 SearchReturns map[string][]models.ServicePlanFields 13 SearchErr error 14 15 UpdateStub func(models.ServicePlanFields, string, bool) error 16 updateMutex sync.RWMutex 17 updateArgsForCall []struct { 18 arg1 models.ServicePlanFields 19 arg2 string 20 arg3 bool 21 } 22 updateReturns struct { 23 result1 error 24 } 25 26 ListPlansFromManyServicesReturns []models.ServicePlanFields 27 ListPlansFromManyServicesError error 28 } 29 30 func (fake *OldFakeServicePlanRepo) ListPlansFromManyServices(serviceGUIDs []string) (plans []models.ServicePlanFields, err error) { 31 if fake.ListPlansFromManyServicesError != nil { 32 return nil, fake.ListPlansFromManyServicesError 33 } 34 35 if fake.ListPlansFromManyServicesReturns != nil { 36 return fake.ListPlansFromManyServicesReturns, nil 37 } 38 return []models.ServicePlanFields{}, nil 39 } 40 41 func (fake *OldFakeServicePlanRepo) Search(queryParams map[string]string) ([]models.ServicePlanFields, error) { 42 if fake.SearchErr != nil { 43 return nil, fake.SearchErr 44 } 45 46 if queryParams == nil { 47 //return everything 48 var returnPlans []models.ServicePlanFields 49 for _, value := range fake.SearchReturns { 50 returnPlans = append(returnPlans, value...) 51 } 52 return returnPlans, nil 53 } 54 55 searchKey := combineKeys(queryParams) 56 if fake.SearchReturns[searchKey] != nil { 57 return fake.SearchReturns[searchKey], nil 58 } 59 60 return []models.ServicePlanFields{}, nil 61 } 62 63 func combineKeys(mapToCombine map[string]string) string { 64 keys := []string{} 65 for key := range mapToCombine { 66 keys = append(keys, key) 67 } 68 sort.Strings(keys) 69 70 values := []string{} 71 for _, key := range keys { 72 values = append(values, mapToCombine[key]) 73 } 74 75 return strings.Join(values, ":") 76 } 77 78 func (fake *OldFakeServicePlanRepo) Update(arg1 models.ServicePlanFields, arg2 string, arg3 bool) error { 79 fake.updateMutex.Lock() 80 defer fake.updateMutex.Unlock() 81 fake.updateArgsForCall = append(fake.updateArgsForCall, struct { 82 arg1 models.ServicePlanFields 83 arg2 string 84 arg3 bool 85 }{arg1, arg2, arg3}) 86 if fake.UpdateStub != nil { 87 return fake.UpdateStub(arg1, arg2, arg3) 88 } else { 89 return fake.updateReturns.result1 90 } 91 } 92 93 func (fake *OldFakeServicePlanRepo) UpdateCallCount() int { 94 fake.updateMutex.RLock() 95 defer fake.updateMutex.RUnlock() 96 return len(fake.updateArgsForCall) 97 } 98 99 func (fake *OldFakeServicePlanRepo) UpdateArgsForCall(i int) (models.ServicePlanFields, string, bool) { 100 fake.updateMutex.RLock() 101 defer fake.updateMutex.RUnlock() 102 return fake.updateArgsForCall[i].arg1, fake.updateArgsForCall[i].arg2, fake.updateArgsForCall[i].arg3 103 } 104 105 func (fake *OldFakeServicePlanRepo) UpdateReturns(result1 error) { 106 fake.UpdateStub = nil 107 fake.updateReturns = struct { 108 result1 error 109 }{result1} 110 }