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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/environs/jujutest/tests.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:
11
11
        "github.com/juju/juju/environs"
12
12
        "github.com/juju/juju/environs/bootstrap"
13
13
        "github.com/juju/juju/environs/config"
14
 
        "github.com/juju/juju/environs/configstore"
 
14
        "github.com/juju/juju/environs/filestorage"
15
15
        sstesting "github.com/juju/juju/environs/simplestreams/testing"
 
16
        "github.com/juju/juju/environs/storage"
16
17
        envtesting "github.com/juju/juju/environs/testing"
17
18
        "github.com/juju/juju/instance"
18
19
        "github.com/juju/juju/juju/testing"
19
20
        "github.com/juju/juju/jujuclient"
20
21
        "github.com/juju/juju/jujuclient/jujuclienttesting"
21
22
        coretesting "github.com/juju/juju/testing"
22
 
        "github.com/juju/juju/version"
 
23
        jujuversion "github.com/juju/juju/version"
23
24
)
24
25
 
25
26
// Tests is a gocheck suite containing tests verifying juju functionality
34
35
        CloudRegion   string
35
36
        envtesting.ToolsFixture
36
37
        sstesting.TestDataSuite
37
 
        // ConfigStore holds the configuration storage
38
 
        // used when preparing the environment.
39
 
        // This is initialized by SetUpTest.
40
 
        ConfigStore configstore.Storage
41
38
 
42
39
        // ControllerStore holds the controller related informtion
43
40
        // such as controllers, accounts, etc., used when preparing
44
41
        // the environment. This is initialized by SetUpSuite.
45
42
        ControllerStore jujuclient.ClientStore
 
43
        toolsStorage    storage.Storage
46
44
}
47
45
 
48
46
// Open opens an instance of the testing environment.
49
 
func (t *Tests) Open(c *gc.C) environs.Environ {
50
 
        modelName := t.TestConfig["name"].(string)
51
 
        info, err := t.ConfigStore.ReadInfo(configstore.EnvironInfoName(modelName, modelName))
52
 
        c.Assert(err, jc.ErrorIsNil)
53
 
        cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())
54
 
        c.Assert(err, jc.ErrorIsNil)
 
47
func (t *Tests) Open(c *gc.C, cfg *config.Config) environs.Environ {
55
48
        e, err := environs.New(cfg)
56
49
        c.Assert(err, gc.IsNil, gc.Commentf("opening environ %#v", cfg.AllAttrs()))
57
50
        c.Assert(e, gc.NotNil)
60
53
 
61
54
// Prepare prepares an instance of the testing environment.
62
55
func (t *Tests) Prepare(c *gc.C) environs.Environ {
63
 
        cfg, err := config.New(config.NoDefaults, t.TestConfig)
64
 
        c.Assert(err, jc.ErrorIsNil)
65
56
        credential := t.Credential
66
57
        if credential.AuthType() == "" {
67
58
                credential = cloud.NewEmptyCredential()
68
59
        }
69
 
        args := environs.PrepareForBootstrapParams{
70
 
                Config:        cfg,
71
 
                Credentials:   credential,
72
 
                CloudEndpoint: t.CloudEndpoint,
73
 
                CloudRegion:   t.CloudRegion,
 
60
        args := environs.PrepareParams{
 
61
                BaseConfig:     t.TestConfig,
 
62
                Credential:     credential,
 
63
                ControllerName: t.TestConfig["name"].(string),
 
64
                CloudName:      t.TestConfig["type"].(string),
 
65
                CloudEndpoint:  t.CloudEndpoint,
 
66
                CloudRegion:    t.CloudRegion,
74
67
        }
75
 
        e, err := environs.Prepare(envtesting.BootstrapContext(c), t.ConfigStore, t.ControllerStore, args.Config.Name(), args)
 
68
        e, err := environs.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, args)
76
69
        c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig))
77
70
        c.Assert(e, gc.NotNil)
78
71
        return e
82
75
        storageDir := c.MkDir()
83
76
        t.DefaultBaseURL = "file://" + storageDir + "/tools"
84
77
        t.ToolsFixture.SetUpTest(c)
85
 
        t.UploadFakeToolsToDirectory(c, storageDir, "released", "released")
86
 
        t.ConfigStore = configstore.NewMem()
 
78
        stor, err := filestorage.NewFileStorageWriter(storageDir)
 
79
        c.Assert(err, jc.ErrorIsNil)
 
80
        t.UploadFakeTools(c, stor, "released", "released")
 
81
        t.toolsStorage = stor
87
82
        t.ControllerStore = jujuclienttesting.NewMemStore()
88
83
}
89
84
 
94
89
func (t *Tests) TestStartStop(c *gc.C) {
95
90
        e := t.Prepare(c)
96
91
        cfg, err := e.Config().Apply(map[string]interface{}{
97
 
                "agent-version": version.Current.String(),
 
92
                "agent-version": jujuversion.Current.String(),
98
93
        })
99
94
        c.Assert(err, jc.ErrorIsNil)
100
95
        err = e.SetConfig(cfg)
150
145
        c.Assert(err, jc.ErrorIsNil)
151
146
        c.Assert(controllerInstances, gc.Not(gc.HasLen), 0)
152
147
 
153
 
        e2 := t.Open(c)
 
148
        e2 := t.Open(c, e.Config())
154
149
        controllerInstances2, err := e2.ControllerInstances()
155
150
        c.Assert(err, jc.ErrorIsNil)
156
151
        c.Assert(controllerInstances2, gc.Not(gc.HasLen), 0)
157
152
        c.Assert(controllerInstances2, jc.SameContents, controllerInstances)
158
153
 
159
 
        err = environs.Destroy(e2.Config().Name(), e2, t.ConfigStore, t.ControllerStore)
 
154
        err = environs.Destroy(e2.Config().Name(), e2, t.ControllerStore)
160
155
        c.Assert(err, jc.ErrorIsNil)
161
156
 
162
157
        // Prepare again because Destroy invalidates old environments.
165
160
        err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), e3, bootstrap.BootstrapParams{})
166
161
        c.Assert(err, jc.ErrorIsNil)
167
162
 
168
 
        err = environs.Destroy(e3.Config().Name(), e3, t.ConfigStore, t.ControllerStore)
 
163
        err = environs.Destroy(e3.Config().Name(), e3, t.ControllerStore)
169
164
        c.Assert(err, jc.ErrorIsNil)
170
165
}