~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/jujuclient/jujuclienttesting/stub.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        CredentialForCloudFunc func(string) (*cloud.CloudCredential, error)
36
36
        AllCredentialsFunc     func() (map[string]cloud.CloudCredential, error)
37
37
        UpdateCredentialFunc   func(cloudName string, details cloud.CloudCredential) error
 
38
 
 
39
        BootstrapConfigForControllerFunc func(controllerName string) (*jujuclient.BootstrapConfig, error)
 
40
        UpdateBootstrapConfigFunc        func(controllerName string, cfg jujuclient.BootstrapConfig) error
38
41
}
39
42
 
40
43
func NewStubStore() *StubStore {
101
104
        result.UpdateCredentialFunc = func(cloudName string, details cloud.CloudCredential) error {
102
105
                return result.Stub.NextErr()
103
106
        }
 
107
 
 
108
        result.BootstrapConfigForControllerFunc = func(controllerName string) (*jujuclient.BootstrapConfig, error) {
 
109
                return nil, result.Stub.NextErr()
 
110
        }
 
111
        result.UpdateBootstrapConfigFunc = func(controllerName string, cfg jujuclient.BootstrapConfig) error {
 
112
                return result.Stub.NextErr()
 
113
        }
104
114
        return result
105
115
}
106
116
 
 
117
// WrapClientStore wraps a ClientStore with a StubStore, where each method calls
 
118
// through to the wrapped store. This can be used to override specific
 
119
// methods, or just to check which calls have been made.
 
120
func WrapClientStore(underlying jujuclient.ClientStore) *StubStore {
 
121
        stub := NewStubStore()
 
122
        stub.AllControllersFunc = underlying.AllControllers
 
123
        stub.ControllerByNameFunc = underlying.ControllerByName
 
124
        stub.UpdateControllerFunc = underlying.UpdateController
 
125
        stub.RemoveControllerFunc = underlying.RemoveController
 
126
        stub.UpdateModelFunc = underlying.UpdateModel
 
127
        stub.SetCurrentModelFunc = underlying.SetCurrentModel
 
128
        stub.RemoveModelFunc = underlying.RemoveModel
 
129
        stub.AllModelsFunc = underlying.AllModels
 
130
        stub.CurrentModelFunc = underlying.CurrentModel
 
131
        stub.ModelByNameFunc = underlying.ModelByName
 
132
        stub.UpdateAccountFunc = underlying.UpdateAccount
 
133
        stub.SetCurrentAccountFunc = underlying.SetCurrentAccount
 
134
        stub.AllAccountsFunc = underlying.AllAccounts
 
135
        stub.CurrentAccountFunc = underlying.CurrentAccount
 
136
        stub.AccountByNameFunc = underlying.AccountByName
 
137
        stub.RemoveAccountFunc = underlying.RemoveAccount
 
138
        stub.BootstrapConfigForControllerFunc = underlying.BootstrapConfigForController
 
139
        stub.UpdateBootstrapConfigFunc = underlying.UpdateBootstrapConfig
 
140
        return stub
 
141
}
 
142
 
107
143
// AllControllers implements ControllersGetter.AllControllers
108
144
func (c *StubStore) AllControllers() (map[string]jujuclient.ControllerDetails, error) {
109
145
        c.MethodCall(c, "AllControllers")
217
253
        c.MethodCall(c, "UpdateCredential", cloudName, details)
218
254
        return c.UpdateCredentialFunc(cloudName, details)
219
255
}
 
256
 
 
257
// BootstrapConfigForController implements BootstrapConfigGetter.
 
258
func (c *StubStore) BootstrapConfigForController(controllerName string) (*jujuclient.BootstrapConfig, error) {
 
259
        c.MethodCall(c, "BootstrapConfigForController", controllerName)
 
260
        return c.BootstrapConfigForControllerFunc(controllerName)
 
261
}
 
262
 
 
263
// UpdateBootstrapConfig implements BootstrapConfigUpdater.
 
264
func (c *StubStore) UpdateBootstrapConfig(controllerName string, cfg jujuclient.BootstrapConfig) error {
 
265
        c.MethodCall(c, "UpdateBootstrapConfig", controllerName, cfg)
 
266
        return c.UpdateBootstrapConfigFunc(controllerName, cfg)
 
267
}