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

« back to all changes in this revision

Viewing changes to environs/open_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:
19
19
        "launchpad.net/juju-core/provider/dummy"
20
20
        "launchpad.net/juju-core/testing"
21
21
        jc "launchpad.net/juju-core/testing/checkers"
 
22
        "launchpad.net/juju-core/testing/testbase"
22
23
)
23
24
 
24
25
type OpenSuite struct {
 
26
        testbase.LoggingSuite
25
27
        envtesting.ToolsFixture
26
28
}
27
29
 
52
54
 
53
55
func (OpenSuite) TestNewFromName(c *gc.C) {
54
56
        defer testing.MakeFakeHome(c, testing.MultipleEnvConfigNoDefault, testing.SampleCertName).Restore()
55
 
        e, err := environs.NewFromName("erewhemos", configstore.NewMem())
 
57
        store := configstore.NewMem()
 
58
        e, err := environs.PrepareFromName("erewhemos", store)
56
59
        c.Assert(err, gc.IsNil)
57
 
        c.Assert(e.Name(), gc.Equals, "erewhemos")
58
 
        c.Assert(func() { e.Storage() }, gc.PanicMatches, "environment .* is not prepared")
59
 
}
60
 
 
61
 
func (OpenSuite) TestNewFromNameNoDefault(c *gc.C) {
62
 
        defer testing.MakeFakeHome(c, testing.MultipleEnvConfigNoDefault, testing.SampleCertName).Restore()
63
 
 
64
 
        e, err := environs.NewFromName("", configstore.NewMem())
65
 
        c.Assert(err, gc.ErrorMatches, "no default environment found")
66
 
        c.Assert(e, gc.IsNil)
67
 
}
68
 
 
69
 
func (OpenSuite) TestNewFromNameDefault(c *gc.C) {
70
 
        defer testing.MakeFakeHome(c, testing.SingleEnvConfig, testing.SampleCertName).Restore()
71
 
        e, err := environs.NewFromName("", configstore.NewMem())
 
60
 
 
61
        e, err = environs.NewFromName("erewhemos", store)
72
62
        c.Assert(err, gc.IsNil)
73
63
        c.Assert(e.Name(), gc.Equals, "erewhemos")
74
64
}
111
101
        ))
112
102
        c.Assert(err, gc.IsNil)
113
103
        e, err := environs.New(cfg)
114
 
        c.Assert(err, gc.IsNil)
115
 
        c.Assert(func() { e.Storage() }, gc.PanicMatches, "environment .* is not prepared")
 
104
        c.Assert(err, gc.ErrorMatches, "environment is not prepared")
 
105
        c.Assert(e, gc.IsNil)
116
106
}
117
107
 
118
108
func (OpenSuite) TestPrepare(c *gc.C) {
134
124
        c.Assert(err, gc.IsNil)
135
125
        c.Assert(info.Initialized(), jc.IsTrue)
136
126
        c.Assert(info.BootstrapConfig(), gc.DeepEquals, env.Config().AllAttrs())
 
127
        c.Logf("bootstrap config: %#v", info.BootstrapConfig())
137
128
 
138
129
        // Check that the CA cert was generated.
139
130
        cfgCertPEM, cfgCertOK := env.Config().CACert()
209
200
 
210
201
        // Check that the environment has actually been destroyed
211
202
        // and that the config info has been destroyed too.
212
 
        c.Assert(func() { e.Storage() }, gc.PanicMatches, "environment.* is not prepared")
 
203
        _, _, err = e.StateInfo()
 
204
        c.Assert(err, gc.ErrorMatches, "environment has been destroyed")
213
205
        _, err = store.ReadInfo(e.Name())
214
206
        c.Assert(err, jc.Satisfies, errors.IsNotFoundError)
215
207
}
221
213
                        "name":         "erewhemos",
222
214
                },
223
215
        ))
224
 
        c.Assert(err, gc.IsNil)
225
 
        c.Assert(func() { e.Storage() }, gc.PanicMatches, "environment .* is not prepared")
 
216
        c.Assert(err, gc.ErrorMatches, "environment is not prepared")
 
217
        c.Assert(e, gc.IsNil)
226
218
}
227
219
 
228
220
const checkEnv = `