~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to juju/apiconn_test.go

  • Committer: Tarmac
  • Author(s): Roger Peppe, John Arbash Meinel
  • Date: 2013-10-02 12:38:13 UTC
  • mfrom: (1717.1.42 375-dummy-prepare-state-id)
  • Revision ID: tarmac-20131002123813-3tidl1lj00d3a29c
[r=rogpeppe] environs/dummy: add state-id

This makes the dummy provider more like the other
providers in that the Environ does not refer
directly to the bootstrapped state, but is looked
up when operations are performed on it.

This is also a test case for adding attributes at Prepare
time - many tests needed changing to correctly
deal with this.

https://codereview.appspot.com/14207046/

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
        // and checking that the connection happens within that
81
81
        // time.
82
82
        defer testbase.PatchValue(juju.ProviderConnectDelay, coretesting.LongWait).Restore()
83
 
        bootstrapEnv(c, coretesting.SampleEnvName, nil)
 
83
        bootstrapEnv(c, coretesting.SampleEnvName, defaultConfigStore(c))
84
84
 
85
85
        startTime := time.Now()
86
86
        apiclient, err := juju.NewAPIClientFromName("")
95
95
func (*NewAPIClientSuite) TestNameNotDefault(c *gc.C) {
96
96
        defer coretesting.MakeMultipleEnvHome(c).Restore()
97
97
        envName := coretesting.SampleCertName + "-2"
98
 
        bootstrapEnv(c, envName, nil)
 
98
        bootstrapEnv(c, envName, defaultConfigStore(c))
99
99
        apiclient, err := juju.NewAPIClientFromName(envName)
100
100
        c.Assert(err, gc.IsNil)
101
101
        defer apiclient.Close()
182
182
 
183
183
func (*NewAPIClientSuite) TestWithSlowInfoConnect(c *gc.C) {
184
184
        defer coretesting.MakeSampleHome(c).Restore()
185
 
        bootstrapEnv(c, coretesting.SampleEnvName, nil)
186
 
        store := newConfigStore(coretesting.SampleEnvName, &environInfo{
187
 
                endpoint: configstore.APIEndpoint{
188
 
                        Addresses: []string{"infoapi.com"},
189
 
                },
190
 
        })
 
185
        store := configstore.NewMem()
 
186
        bootstrapEnv(c, coretesting.SampleEnvName, store)
 
187
        setEndpointAddress(c, store, coretesting.SampleEnvName, "infoapi.com")
191
188
 
192
189
        infoOpenedState := new(api.State)
193
190
        infoEndpointOpened := make(chan struct{})
231
228
        }
232
229
}
233
230
 
 
231
func setEndpointAddress(c *gc.C, store configstore.Storage, envName string, addr string) {
 
232
        // Populate the environment's info with an endpoint
 
233
        // with a known address.
 
234
        info, err := store.ReadInfo(coretesting.SampleEnvName)
 
235
        c.Assert(err, gc.IsNil)
 
236
        info.SetAPIEndpoint(configstore.APIEndpoint{
 
237
                Addresses: []string{addr},
 
238
                CACert:    "certificated",
 
239
        })
 
240
        err = info.Write()
 
241
        c.Assert(err, gc.IsNil)
 
242
}
 
243
 
234
244
func (*NewAPIClientSuite) TestWithSlowConfigConnect(c *gc.C) {
235
245
        defer coretesting.MakeSampleHome(c).Restore()
236
 
        bootstrapEnv(c, coretesting.SampleEnvName, nil)
237
 
        store := newConfigStore(coretesting.SampleEnvName, &environInfo{
238
 
                endpoint: configstore.APIEndpoint{
239
 
                        Addresses: []string{"infoapi.com"},
240
 
                },
241
 
        })
 
246
 
 
247
        store := configstore.NewMem()
 
248
        bootstrapEnv(c, coretesting.SampleEnvName, store)
 
249
        setEndpointAddress(c, store, coretesting.SampleEnvName, "infoapi.com")
242
250
 
243
251
        infoOpenedState := new(api.State)
244
252
        infoEndpointOpened := make(chan struct{})
300
308
        }
301
309
}
302
310
 
303
 
func (*NewAPIClientSuite) TestBothErrror(c *gc.C) {
 
311
func (*NewAPIClientSuite) TestBothError(c *gc.C) {
304
312
        defer coretesting.MakeSampleHome(c).Restore()
305
 
        bootstrapEnv(c, coretesting.SampleEnvName, nil)
306
 
        store := newConfigStore(coretesting.SampleEnvName, &environInfo{
307
 
                endpoint: configstore.APIEndpoint{
308
 
                        Addresses: []string{"infoapi.com"},
309
 
                },
310
 
        })
 
313
        store := configstore.NewMem()
 
314
        bootstrapEnv(c, coretesting.SampleEnvName, store)
 
315
        setEndpointAddress(c, store, coretesting.SampleEnvName, "infoapi.com")
311
316
 
312
317
        defer testbase.PatchValue(juju.ProviderConnectDelay, 0*time.Second).Restore()
313
318
        apiOpen := func(info *api.Info, opts api.DialOpts) (*api.State, error) {
322
327
        c.Check(st, gc.IsNil)
323
328
}
324
329
 
 
330
func defaultConfigStore(c *gc.C) configstore.Storage {
 
331
        store, err := configstore.Default()
 
332
        c.Assert(err, gc.IsNil)
 
333
        return store
 
334
}
 
335
 
325
336
// TODO(jam): 2013-08-27 This should move somewhere in api.*
326
337
func (*NewAPIClientSuite) TestMultipleCloseOk(c *gc.C) {
327
338
        defer coretesting.MakeSampleHome(c).Restore()
328
 
        bootstrapEnv(c, "", nil)
 
339
        bootstrapEnv(c, "", defaultConfigStore(c))
329
340
        client, _ := juju.NewAPIClientFromName("")
330
341
        c.Assert(client.Close(), gc.IsNil)
331
342
        c.Assert(client.Close(), gc.IsNil)