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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/lxd/testing_test.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:
26
26
        "github.com/juju/juju/testing"
27
27
        "github.com/juju/juju/tools"
28
28
        "github.com/juju/juju/tools/lxdclient"
29
 
        "github.com/juju/juju/version"
 
29
        "github.com/juju/version"
30
30
)
31
31
 
32
32
// These values are stub LXD client credentials for use in tests.
70
70
// These are stub config values for use in tests.
71
71
var (
72
72
        ConfigAttrs = testing.FakeConfig().Merge(testing.Attrs{
73
 
                "type":        "lxd",
74
 
                "namespace":   "",
75
 
                "remote-url":  "",
76
 
                "client-cert": "",
77
 
                "client-key":  "",
78
 
                "server-cert": "",
79
 
                "uuid":        "2d02eeac-9dbb-11e4-89d3-123b93f75cba",
 
73
                "type":            "lxd",
 
74
                "namespace":       "",
 
75
                "remote-url":      "",
 
76
                "client-cert":     "",
 
77
                "client-key":      "",
 
78
                "server-cert":     "",
 
79
                "uuid":            "2d02eeac-9dbb-11e4-89d3-123b93f75cba",
 
80
                "controller-uuid": "bfef02f1-932a-425a-a102-62175dcabd1d",
80
81
        })
81
82
)
82
83
 
119
120
                s.osPathOrig =
120
121
                        "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
121
122
        }
122
 
        s.IsolationSuite.SetUpTest(c)
 
123
        s.IsolationSuite.SetUpSuite(c)
123
124
}
124
125
 
125
126
func (s *BaseSuiteUnpatched) SetUpTest(c *gc.C) {
204
205
        ecfg, err := newValidConfig(cfg, configDefaults)
205
206
        c.Assert(err, jc.ErrorIsNil)
206
207
        s.EnvConfig = ecfg
207
 
        uuid, _ := cfg.UUID()
 
208
        uuid := cfg.UUID()
208
209
        s.Env.uuid = uuid
209
210
        s.Env.ecfg = s.EnvConfig
210
211
        s.Prefix = "juju-" + uuid + "-"
266
267
        BaseSuiteUnpatched
267
268
 
268
269
        Stub       *gitjujutesting.Stub
269
 
        Client     *stubClient
 
270
        Client     *StubClient
270
271
        Firewaller *stubFirewaller
271
272
        Common     *stubCommon
272
273
        Policy     *stubPolicy
273
274
}
274
275
 
 
276
func (s *BaseSuite) SetUpSuite(c *gc.C) {
 
277
        s.BaseSuiteUnpatched.SetUpSuite(c)
 
278
        // Do this *before* s.initEnv() gets called in BaseSuiteUnpatched.SetUpTest
 
279
        s.PatchValue(&asNonLocal, s.asNonLocal)
 
280
}
 
281
 
275
282
func (s *BaseSuite) SetUpTest(c *gc.C) {
276
 
        // Do this *before* s.initEnv() gets called.
277
 
        s.PatchValue(&asNonLocal, s.asNonLocal)
278
 
 
279
283
        s.BaseSuiteUnpatched.SetUpTest(c)
280
284
 
281
285
        s.Stub = &gitjujutesting.Stub{}
282
 
        s.Client = &stubClient{stub: s.Stub}
 
286
        s.Client = &StubClient{Stub: s.Stub}
283
287
        s.Firewaller = &stubFirewaller{stub: s.Stub}
284
288
        s.Common = &stubCommon{stub: s.Stub}
285
289
        s.Policy = &stubPolicy{stub: s.Stub}
470
474
        return s.Arches, nil
471
475
}
472
476
 
473
 
type stubClient struct {
474
 
        stub *gitjujutesting.Stub
 
477
type StubClient struct {
 
478
        *gitjujutesting.Stub
475
479
 
476
480
        Insts []lxdclient.Instance
477
481
        Inst  *lxdclient.Instance
478
482
}
479
483
 
480
 
func (conn *stubClient) Instances(prefix string, statuses ...string) ([]lxdclient.Instance, error) {
481
 
        conn.stub.AddCall("Instances", prefix, statuses)
482
 
        if err := conn.stub.NextErr(); err != nil {
 
484
func (conn *StubClient) Instances(prefix string, statuses ...string) ([]lxdclient.Instance, error) {
 
485
        conn.AddCall("Instances", prefix, statuses)
 
486
        if err := conn.NextErr(); err != nil {
483
487
                return nil, errors.Trace(err)
484
488
        }
485
489
 
486
490
        return conn.Insts, nil
487
491
}
488
492
 
489
 
func (conn *stubClient) AddInstance(spec lxdclient.InstanceSpec) (*lxdclient.Instance, error) {
490
 
        conn.stub.AddCall("AddInstance", spec)
491
 
        if err := conn.stub.NextErr(); err != nil {
 
493
func (conn *StubClient) AddInstance(spec lxdclient.InstanceSpec) (*lxdclient.Instance, error) {
 
494
        conn.AddCall("AddInstance", spec)
 
495
        if err := conn.NextErr(); err != nil {
492
496
                return nil, errors.Trace(err)
493
497
        }
494
498
 
495
499
        return conn.Inst, nil
496
500
}
497
501
 
498
 
func (conn *stubClient) RemoveInstances(prefix string, ids ...string) error {
499
 
        conn.stub.AddCall("RemoveInstances", prefix, ids)
500
 
        if err := conn.stub.NextErr(); err != nil {
501
 
                return errors.Trace(err)
502
 
        }
503
 
 
504
 
        return nil
505
 
}
506
 
 
507
 
func (conn *stubClient) EnsureImageExists(series string) error {
508
 
        conn.stub.AddCall("EnsureImageExists", series)
509
 
        if err := conn.stub.NextErr(); err != nil {
510
 
                return errors.Trace(err)
511
 
        }
512
 
 
513
 
        return nil
514
 
}
515
 
 
516
 
func (conn *stubClient) Addresses(name string) ([]network.Address, error) {
517
 
        conn.stub.AddCall("Addresses", name)
518
 
        if err := conn.stub.NextErr(); err != nil {
 
502
func (conn *StubClient) RemoveInstances(prefix string, ids ...string) error {
 
503
        conn.AddCall("RemoveInstances", prefix, ids)
 
504
        if err := conn.NextErr(); err != nil {
 
505
                return errors.Trace(err)
 
506
        }
 
507
 
 
508
        return nil
 
509
}
 
510
 
 
511
func (conn *StubClient) EnsureImageExists(series string, _ []lxdclient.Remote, _ func(string)) error {
 
512
        conn.AddCall("EnsureImageExists", series)
 
513
        if err := conn.NextErr(); err != nil {
 
514
                return errors.Trace(err)
 
515
        }
 
516
 
 
517
        return nil
 
518
}
 
519
 
 
520
func (conn *StubClient) Addresses(name string) ([]network.Address, error) {
 
521
        conn.AddCall("Addresses", name)
 
522
        if err := conn.NextErr(); err != nil {
519
523
                return nil, errors.Trace(err)
520
524
        }
521
525