1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
gc "launchpad.net/gocheck"
13
"launchpad.net/juju-core/juju/testing"
14
coretesting "launchpad.net/juju-core/testing"
17
var _ = gc.Suite(&observerSuite{})
19
type observerSuite struct {
23
func (s *observerSuite) TestWaitsForValidEnviron(c *gc.C) {
24
obs, err := newEnvironObserver(s.State, nil)
25
c.Assert(err, gc.IsNil)
27
stateConfig, err := s.State.EnvironConfig()
28
c.Assert(err, gc.IsNil)
29
c.Assert(env.Config().AllAttrs(), gc.DeepEquals, stateConfig.AllAttrs())
32
func (s *observerSuite) TestEnvironmentChanges(c *gc.C) {
33
originalConfig, err := s.State.EnvironConfig()
34
c.Assert(err, gc.IsNil)
36
logc := make(logChan, 1009)
37
c.Assert(loggo.RegisterWriter("testing", logc, loggo.WARNING), gc.IsNil)
38
defer loggo.RemoveWriter("testing")
40
obs, err := newEnvironObserver(s.State, nil)
41
c.Assert(err, gc.IsNil)
44
c.Assert(env.Config().AllAttrs(), gc.DeepEquals, originalConfig.AllAttrs())
47
// Change to an invalid configuration and check
48
// that the observer's environment remains the same.
49
testing.ChangeEnvironConfig(c, s.State, func(attrs coretesting.Attrs) coretesting.Attrs {
50
oldType = attrs["type"].(string)
51
return attrs.Merge(coretesting.Attrs{
57
// Wait for the observer to register the invalid environment
58
timeout := time.After(coretesting.LongWait)
63
if strings.Contains(msg, "error creating Environ") {
67
c.Fatalf("timed out waiting to see broken environment")
70
// Check that the returned environ is still the same.
72
c.Assert(env.Config().AllAttrs(), gc.DeepEquals, originalConfig.AllAttrs())
74
// Change the environment back to a valid configuration
75
// with a different name and check that we see it.
76
testing.ChangeEnvironConfig(c, s.State, func(attrs coretesting.Attrs) coretesting.Attrs {
77
return attrs.Merge(coretesting.Attrs{
84
for a := coretesting.LongAttempt.Start(); a.Next(); {
87
c.Fatalf("timed out waiting for new environ")
89
if env.Config().Name() == "a-new-name" {
95
type logChan chan string
97
func (logc logChan) Write(level loggo.Level, name, filename string, line int, timestamp time.Time, message string) {