OLD | NEW |
1 // Copyright 2011, 2012, 2013 Canonical Ltd. | 1 // Copyright 2011, 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package environs_test | 4 package environs_test |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "os" | 8 "os" |
9 "path/filepath" | 9 "path/filepath" |
10 "sort" | 10 "sort" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 defer testing.MakeFakeHomeNoEnvironments(c, "only").Restore() | 100 defer testing.MakeFakeHomeNoEnvironments(c, "only").Restore() |
101 content := ` | 101 content := ` |
102 environments: | 102 environments: |
103 valid: | 103 valid: |
104 type: dummy | 104 type: dummy |
105 state-server: false | 105 state-server: false |
106 deprecated: | 106 deprecated: |
107 type: dummy | 107 type: dummy |
108 state-server: false | 108 state-server: false |
109 tools-url: aknowndeprecatedfield | 109 tools-url: aknowndeprecatedfield |
| 110 lxc-use-clone: true |
110 ` | 111 ` |
111 tw := &loggo.TestWriter{} | 112 tw := &loggo.TestWriter{} |
112 // we only capture Warning or above | 113 // we only capture Warning or above |
113 c.Assert(loggo.RegisterWriter("invalid-env-tester", tw, loggo.WARNING),
gc.IsNil) | 114 c.Assert(loggo.RegisterWriter("invalid-env-tester", tw, loggo.WARNING),
gc.IsNil) |
114 defer loggo.RemoveWriter("invalid-env-tester") | 115 defer loggo.RemoveWriter("invalid-env-tester") |
115 | 116 |
116 envs, err := environs.ReadEnvironsBytes([]byte(content)) | 117 envs, err := environs.ReadEnvironsBytes([]byte(content)) |
117 c.Check(err, gc.IsNil) | 118 c.Check(err, gc.IsNil) |
118 names := envs.Names() | 119 names := envs.Names() |
119 sort.Strings(names) | 120 sort.Strings(names) |
120 c.Check(names, gc.DeepEquals, []string{"deprecated", "valid"}) | 121 c.Check(names, gc.DeepEquals, []string{"deprecated", "valid"}) |
121 // There should be no warning in the log | 122 // There should be no warning in the log |
122 c.Check(tw.Log, gc.HasLen, 0) | 123 c.Check(tw.Log, gc.HasLen, 0) |
123 // Now we actually grab the 'valid' entry | 124 // Now we actually grab the 'valid' entry |
124 _, err = envs.Config("valid") | 125 _, err = envs.Config("valid") |
125 c.Check(err, gc.IsNil) | 126 c.Check(err, gc.IsNil) |
126 // And still we have no warnings | 127 // And still we have no warnings |
127 c.Check(tw.Log, gc.HasLen, 0) | 128 c.Check(tw.Log, gc.HasLen, 0) |
128 // Only once we grab the deprecated one do we see any warnings | 129 // Only once we grab the deprecated one do we see any warnings |
129 _, err = envs.Config("deprecated") | 130 _, err = envs.Config("deprecated") |
130 c.Check(err, gc.IsNil) | 131 c.Check(err, gc.IsNil) |
131 » c.Check(tw.Log, gc.HasLen, 1) | 132 » c.Check(tw.Log, gc.HasLen, 2) |
132 } | 133 } |
133 | 134 |
134 func (*suite) TestNoHomeBeforeConfig(c *gc.C) { | 135 func (*suite) TestNoHomeBeforeConfig(c *gc.C) { |
135 // Test that we don't actually need HOME set until we call envs.Config() | 136 // Test that we don't actually need HOME set until we call envs.Config() |
136 // Because of this, we intentionally do *not* call testing.MakeFakeHomeN
oEnvironments() | 137 // Because of this, we intentionally do *not* call testing.MakeFakeHomeN
oEnvironments() |
137 content := ` | 138 content := ` |
138 environments: | 139 environments: |
139 valid: | 140 valid: |
140 type: dummy | 141 type: dummy |
141 amazon: | 142 amazon: |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 `.*Config attribute "tools-url" \(aknowndeprecatedfield\) is dep
recated and will be ignored since` + | 449 `.*Config attribute "tools-url" \(aknowndeprecatedfield\) is dep
recated and will be ignored since` + |
449 `the new tools URL attribute "tools-metadata-url".*`) | 450 `the new tools URL attribute "tools-metadata-url".*`) |
450 s.checkDeprecationWarning(c, attrs, expected) | 451 s.checkDeprecationWarning(c, attrs, expected) |
451 } | 452 } |
452 | 453 |
453 func (s *ConfigDeprecationSuite) TestDeprecatedTypeNullWarning(c *gc.C) { | 454 func (s *ConfigDeprecationSuite) TestDeprecatedTypeNullWarning(c *gc.C) { |
454 attrs := testing.Attrs{"type": "null"} | 455 attrs := testing.Attrs{"type": "null"} |
455 expected := `Provider type \"null\" has been renamed to \"manual\"\.Plea
se update your environment configuration\.` | 456 expected := `Provider type \"null\" has been renamed to \"manual\"\.Plea
se update your environment configuration\.` |
456 s.checkDeprecationWarning(c, attrs, expected) | 457 s.checkDeprecationWarning(c, attrs, expected) |
457 } | 458 } |
| 459 |
| 460 func (s *ConfigDeprecationSuite) TestDeprecatedLxcUseCloneWarning(c *gc.C) { |
| 461 attrs := testing.Attrs{"lxc-use-clone": true} |
| 462 expected := `Config attribute \"lxc-use-clone\" has been renamed to \"lx
c-clone\".Please update your environment configuration\.` |
| 463 s.checkDeprecationWarning(c, attrs, expected) |
| 464 } |
OLD | NEW |