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"
25
26
// Tests is a gocheck suite containing tests verifying juju functionality
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
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
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)
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()
69
args := environs.PrepareForBootstrapParams{
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,
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)
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")
87
82
t.ControllerStore = jujuclienttesting.NewMemStore()
94
89
func (t *Tests) TestStartStop(c *gc.C) {
96
91
cfg, err := e.Config().Apply(map[string]interface{}{
97
"agent-version": version.Current.String(),
92
"agent-version": jujuversion.Current.String(),
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)
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)
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)
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)
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)