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

     1  package fakes
     2  
     3  import (
     4  	"sort"
     5  	"strings"
     6  	"sync"
     7  
     8  	"github.com/cloudfoundry/cli/cf/models"
     9  )
    10  
    11  type FakeServicePlanRepo 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  
    27  func (fake *FakeServicePlanRepo) Search(queryParams map[string]string) ([]models.ServicePlanFields, error) {
    28  	if fake.SearchErr != nil {
    29  		return nil, fake.SearchErr
    30  	}
    31  
    32  	if queryParams == nil {
    33  		//return everything
    34  		var returnPlans []models.ServicePlanFields
    35  		for _, value := range fake.SearchReturns {
    36  			returnPlans = append(returnPlans, value...)
    37  		}
    38  		return returnPlans, nil
    39  	}
    40  
    41  	searchKey := combineKeys(queryParams)
    42  	if fake.SearchReturns[searchKey] != nil {
    43  		return fake.SearchReturns[searchKey], nil
    44  	}
    45  
    46  	return []models.ServicePlanFields{}, nil
    47  }
    48  
    49  func combineKeys(mapToCombine map[string]string) string {
    50  	keys := []string{}
    51  	for key, _ := range mapToCombine {
    52  		keys = append(keys, key)
    53  	}
    54  	sort.Strings(keys)
    55  
    56  	values := []string{}
    57  	for _, key := range keys {
    58  		values = append(values, mapToCombine[key])
    59  	}
    60  
    61  	return strings.Join(values, ":")
    62  }
    63  
    64  func (fake *FakeServicePlanRepo) Update(arg1 models.ServicePlanFields, arg2 string, arg3 bool) error {
    65  	fake.updateMutex.Lock()
    66  	defer fake.updateMutex.Unlock()
    67  	fake.updateArgsForCall = append(fake.updateArgsForCall, struct {
    68  		arg1 models.ServicePlanFields
    69  		arg2 string
    70  		arg3 bool
    71  	}{arg1, arg2, arg3})
    72  	if fake.UpdateStub != nil {
    73  		return fake.UpdateStub(arg1, arg2, arg3)
    74  	} else {
    75  		return fake.updateReturns.result1
    76  	}
    77  }
    78  
    79  func (fake *FakeServicePlanRepo) UpdateCallCount() int {
    80  	fake.updateMutex.RLock()
    81  	defer fake.updateMutex.RUnlock()
    82  	return len(fake.updateArgsForCall)
    83  }
    84  
    85  func (fake *FakeServicePlanRepo) UpdateArgsForCall(i int) (models.ServicePlanFields, string, bool) {
    86  	fake.updateMutex.RLock()
    87  	defer fake.updateMutex.RUnlock()
    88  	return fake.updateArgsForCall[i].arg1, fake.updateArgsForCall[i].arg2, fake.updateArgsForCall[i].arg3
    89  }
    90  
    91  func (fake *FakeServicePlanRepo) UpdateReturns(result1 error) {
    92  	fake.UpdateStub = nil
    93  	fake.updateReturns = struct {
    94  		result1 error
    95  	}{result1}
    96  }