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

« back to all changes in this revision

Viewing changes to worker/environ_test.go

[r=rogpeppe] worker/addressupdater: wire up

It could do with some more comprehensive
testing, but it might be OK to land anyway.

https://codereview.appspot.com/14306043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        "launchpad.net/tomb"
11
11
 
12
12
        "launchpad.net/juju-core/environs"
13
 
        "launchpad.net/juju-core/environs/config"
14
13
        "launchpad.net/juju-core/juju/testing"
15
14
        "launchpad.net/juju-core/state"
16
15
        coretesting "launchpad.net/juju-core/testing"
17
16
        "launchpad.net/juju-core/worker"
18
17
)
19
18
 
20
 
type suite struct {
 
19
type waitForEnvironSuite struct {
21
20
        testing.JujuConnSuite
22
21
}
23
22
 
24
 
var _ = gc.Suite(&suite{})
 
23
var _ = gc.Suite(&waitForEnvironSuite{})
25
24
 
26
25
func TestPackage(t *stdtesting.T) {
27
26
        coretesting.MgoTestPackage(t)
28
27
}
29
28
 
30
 
func (s *suite) TestStop(c *gc.C) {
 
29
func (s *waitForEnvironSuite) TestStop(c *gc.C) {
31
30
        w := s.State.WatchForEnvironConfigChanges()
32
31
        defer stopWatcher(c, w)
33
32
        stop := make(chan struct{})
46
45
        c.Check(err, gc.IsNil)
47
46
}
48
47
 
49
 
func (s *suite) TestInvalidConfig(c *gc.C) {
 
48
func (s *waitForEnvironSuite) TestInvalidConfig(c *gc.C) {
50
49
        // Create an invalid config by taking the current config and
51
50
        // tweaking the provider type.
52
 
        cfg, err := s.State.EnvironConfig()
53
 
        c.Assert(err, gc.IsNil)
54
 
        m := cfg.AllAttrs()
55
 
        m["type"] = "unknown"
56
 
        invalidCfg, err := config.New(config.NoDefaults, m)
57
 
        c.Assert(err, gc.IsNil)
58
 
 
59
 
        err = s.State.SetEnvironConfig(invalidCfg)
60
 
        c.Assert(err, gc.IsNil)
61
 
 
 
51
        var oldType string
 
52
        testing.ChangeEnvironConfig(c, s.State, func(attrs coretesting.Attrs) coretesting.Attrs {
 
53
                oldType = attrs["type"].(string)
 
54
                return attrs.Merge(coretesting.Attrs{"type": "unknown"})
 
55
        })
62
56
        w := s.State.WatchForEnvironConfigChanges()
63
57
        defer stopWatcher(c, w)
64
58
        done := make(chan environs.Environ)
70
64
        // Wait for the loop to process the invalid configuratrion
71
65
        <-worker.LoadedInvalid
72
66
 
73
 
        // Then load a valid configuration back in.
74
 
        m = cfg.AllAttrs()
75
 
        m["secret"] = "environ_test"
76
 
        validCfg, err := config.New(config.NoDefaults, m)
77
 
        c.Assert(err, gc.IsNil)
78
 
 
79
 
        err = s.State.SetEnvironConfig(validCfg)
80
 
        c.Assert(err, gc.IsNil)
81
 
        s.State.StartSync()
 
67
        testing.ChangeEnvironConfig(c, s.State, func(attrs coretesting.Attrs) coretesting.Attrs {
 
68
                return attrs.Merge(coretesting.Attrs{
 
69
                        "type":   oldType,
 
70
                        "secret": "environ_test",
 
71
                })
 
72
        })
82
73
 
83
74
        env := <-done
84
75
        c.Assert(env, gc.NotNil)