OLD | NEW |
1 // Copyright 2013 Joyent Inc. | 1 // Copyright 2013 Joyent Inc. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package joyent_test | 4 package joyent_test |
5 | 5 |
6 import ( | 6 import ( |
| 7 "fmt" |
| 8 "os" |
| 9 |
7 "github.com/juju/testing" | 10 "github.com/juju/testing" |
8 gc "launchpad.net/gocheck" | 11 gc "launchpad.net/gocheck" |
9 | 12 |
10 "launchpad.net/juju-core/environs" | 13 "launchpad.net/juju-core/environs" |
11 "launchpad.net/juju-core/environs/config" | 14 "launchpad.net/juju-core/environs/config" |
12 "launchpad.net/juju-core/provider/joyent" | 15 "launchpad.net/juju-core/provider/joyent" |
| 16 jp "launchpad.net/juju-core/provider/joyent" |
13 coretesting "launchpad.net/juju-core/testing" | 17 coretesting "launchpad.net/juju-core/testing" |
14 "launchpad.net/juju-core/testing/testbase" | |
15 ) | 18 ) |
16 | 19 |
17 func newConfig(c *gc.C, attrs coretesting.Attrs) *config.Config { | 20 func newConfig(c *gc.C, attrs coretesting.Attrs) *config.Config { |
18 attrs = coretesting.FakeConfig().Merge(attrs) | 21 attrs = coretesting.FakeConfig().Merge(attrs) |
19 » cfg, err := config.New(config.NoDefaults, attrs) | 22 » cfg, err := config.New(config.UseDefaults, attrs) |
20 c.Assert(err, gc.IsNil) | 23 c.Assert(err, gc.IsNil) |
21 return cfg | 24 return cfg |
22 } | 25 } |
23 | 26 |
24 func validAttrs() coretesting.Attrs { | 27 func validAttrs() coretesting.Attrs { |
25 return coretesting.FakeConfig().Merge(coretesting.Attrs{ | 28 return coretesting.FakeConfig().Merge(coretesting.Attrs{ |
26 "type": "joyent", | 29 "type": "joyent", |
27 » » "sdc-user": "dstroppa", | 30 » » "sdc-user": "juju-test", |
28 » » "sdc-key-id": "12:c3:a7:cb:a2:29:e2:90:88:3f:04:53:3b:4e:75:40
", | 31 » » "sdc-key-id": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff
", |
29 » » "sdc-region": "us-west-1", | 32 » » "sdc-url": "https://test.api.joyentcloud.com", |
30 » » "manta-user": "dstroppa", | 33 » » "manta-user": "juju-test", |
31 » » "manta-key-id": "12:c3:a7:cb:a2:29:e2:90:88:3f:04:53:3b:4e:75:40
", | 34 » » "manta-key-id": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff
", |
32 » » "manta-region": "us-east", | 35 » » "manta-url": "https://test.manta.joyent.com", |
| 36 » » "key-file": "~/.ssh/provider_id_rsa", |
| 37 » » "algorithm": "rsa-sha256", |
33 "control-dir": "juju-test", | 38 "control-dir": "juju-test", |
| 39 "private-key": "key", |
34 }) | 40 }) |
35 } | 41 } |
36 | 42 |
37 type ConfigSuite struct { | 43 type ConfigSuite struct { |
38 » testbase.LoggingSuite | 44 » coretesting.FakeHomeSuite |
39 originalValues map[string]testing.Restorer | 45 originalValues map[string]testing.Restorer |
40 } | 46 } |
41 | 47 |
42 var _ = gc.Suite(&ConfigSuite{}) | 48 var _ = gc.Suite(&ConfigSuite{}) |
43 | 49 |
44 func (s *ConfigSuite) SetUpSuite(c *gc.C) { | 50 func (s *ConfigSuite) SetUpSuite(c *gc.C) { |
45 » s.PatchEnvironment(joyent.SdcAccount, "tester") | 51 » s.FakeHomeSuite.SetUpSuite(c) |
46 » s.PatchEnvironment(joyent.SdcKeyId, "11:c4:b6:c0:a3:24:22:96:a8:1f:07:53
:3f:8e:14:7a") | 52 » restoreSdcAccount := testing.PatchEnvironment(jp.SdcAccount, "tester") |
47 » s.PatchEnvironment(joyent.MantaUser, "tester") | 53 » s.AddSuiteCleanup(func(*gc.C) { restoreSdcAccount() }) |
48 » s.PatchEnvironment(joyent.MantaKeyId, "11:c4:b6:c0:a3:24:22:96:a8:1f:07:
53:3f:8e:14:7a") | 54 » restoreSdcKeyId := testing.PatchEnvironment(jp.SdcKeyId, "ff:ee:dd:cc:bb
:aa:99:88:77:66:55:44:33:22:11:00") |
| 55 » s.AddSuiteCleanup(func(*gc.C) { restoreSdcKeyId() }) |
| 56 » restoreMantaUser := testing.PatchEnvironment(jp.MantaUser, "tester") |
| 57 » s.AddSuiteCleanup(func(*gc.C) { restoreMantaUser() }) |
| 58 » restoreMantaKeyId := testing.PatchEnvironment(jp.MantaKeyId, "ff:ee:dd:c
c:bb:aa:99:88:77:66:55:44:33:22:11:00") |
| 59 » s.AddSuiteCleanup(func(*gc.C) { restoreMantaKeyId() }) |
| 60 } |
| 61 |
| 62 func (s *ConfigSuite) SetUpTest(c *gc.C) { |
| 63 » s.FakeHomeSuite.SetUpTest(c) |
| 64 » s.AddCleanup(CreateTestKey(c)) |
| 65 » for _, envVar := range joyent.EnvironmentVariables { |
| 66 » » s.PatchEnvironment(envVar, "") |
| 67 » } |
49 } | 68 } |
50 | 69 |
51 var newConfigTests = []struct { | 70 var newConfigTests = []struct { |
52 » info string | 71 » info string |
53 » insert coretesting.Attrs | 72 » insert coretesting.Attrs |
54 » remove []string | 73 » remove []string |
55 » expect coretesting.Attrs | 74 » envVars map[string]string |
56 » err string | 75 » expect coretesting.Attrs |
| 76 » err string |
57 }{{ | 77 }{{ |
58 info: "sdc-user is required", | 78 info: "sdc-user is required", |
59 remove: []string{"sdc-user"}, | 79 remove: []string{"sdc-user"}, |
60 » err: "sdc-user: expected string, got nothing", | 80 » err: ".* cannot get sdc-user value from environment variable .*", |
61 }, { | 81 }, { |
62 info: "sdc-user cannot be empty", | 82 info: "sdc-user cannot be empty", |
63 insert: coretesting.Attrs{"sdc-user": ""}, | 83 insert: coretesting.Attrs{"sdc-user": ""}, |
64 » err: "sdc-user: must not be empty", | 84 » err: ".* cannot get sdc-user value from environment variable .*", |
| 85 }, { |
| 86 » info: "can get sdc-user from env variable", |
| 87 » insert: coretesting.Attrs{"sdc-user": ""}, |
| 88 » expect: coretesting.Attrs{"sdc-user": "tester"}, |
| 89 » envVars: map[string]string{ |
| 90 » » "SDC_ACCOUNT": "tester", |
| 91 » }, |
| 92 }, { |
| 93 » info: "can get sdc-user from env variable, missing from config", |
| 94 » remove: []string{"sdc-user"}, |
| 95 » expect: coretesting.Attrs{"sdc-user": "tester"}, |
| 96 » envVars: map[string]string{ |
| 97 » » "SDC_ACCOUNT": "tester", |
| 98 » }, |
65 }, { | 99 }, { |
66 info: "sdc-key-id is required", | 100 info: "sdc-key-id is required", |
67 remove: []string{"sdc-key-id"}, | 101 remove: []string{"sdc-key-id"}, |
68 » err: "sdc-key-id: expected string, got nothing", | 102 » err: ".* cannot get sdc-key-id value from environment variable .*", |
69 }, { | 103 }, { |
70 info: "sdc-key-id cannot be empty", | 104 info: "sdc-key-id cannot be empty", |
71 insert: coretesting.Attrs{"sdc-key-id": ""}, | 105 insert: coretesting.Attrs{"sdc-key-id": ""}, |
72 » err: "sdc-key-id: must not be empty", | 106 » err: ".* cannot get sdc-key-id value from environment variable .*", |
73 }, { | 107 }, { |
74 » info: "sdc-region is inserted if missing", | 108 » info: "can get sdc-key-id from env variable", |
75 » expect: coretesting.Attrs{"sdc-region": "us-west-1"}, | 109 » insert: coretesting.Attrs{"sdc-key-id": ""}, |
| 110 » expect: coretesting.Attrs{"sdc-key-id": "key"}, |
| 111 » envVars: map[string]string{ |
| 112 » » "SDC_KEY_ID": "key", |
| 113 » }, |
76 }, { | 114 }, { |
77 » info: "sdc-region cannot be empty", | 115 » info: "can get sdc-key-id from env variable, missing from config", |
78 » insert: coretesting.Attrs{"sdc-region": ""}, | 116 » remove: []string{"sdc-key-id"}, |
79 » err: "sdc-region: must not be empty", | 117 » expect: coretesting.Attrs{"sdc-key-id": "key"}, |
| 118 » envVars: map[string]string{ |
| 119 » » "SDC_KEY_ID": "key", |
| 120 » }, |
80 }, { | 121 }, { |
81 » info: "sdc-region is untouched if present", | 122 » info: "sdc-url is inserted if missing", |
82 » insert: coretesting.Attrs{"sdc-region": "us-west-1"}, | 123 » expect: coretesting.Attrs{"sdc-url": "https://test.api.joyentcloud.com"}
, |
83 » expect: coretesting.Attrs{"sdc-region": "us-west-1"}, | 124 }, { |
| 125 » info: "sdc-url cannot be empty", |
| 126 » insert: coretesting.Attrs{"sdc-url": ""}, |
| 127 » err: ".* cannot get sdc-url value from environment variable .*", |
| 128 }, { |
| 129 » info: "sdc-url is untouched if present", |
| 130 » insert: coretesting.Attrs{"sdc-url": "https://test.api.joyentcloud.com"}
, |
| 131 » expect: coretesting.Attrs{"sdc-url": "https://test.api.joyentcloud.com"}
, |
84 }, { | 132 }, { |
85 info: "manta-user is required", | 133 info: "manta-user is required", |
86 remove: []string{"manta-user"}, | 134 remove: []string{"manta-user"}, |
87 » err: "manta-user: expected string, got nothing", | 135 » err: ".* cannot get manta-user value from environment variable .*", |
88 }, { | 136 }, { |
89 info: "manta-user cannot be empty", | 137 info: "manta-user cannot be empty", |
90 insert: coretesting.Attrs{"manta-user": ""}, | 138 insert: coretesting.Attrs{"manta-user": ""}, |
91 » err: "manta-user: must not be empty", | 139 » err: ".* cannot get manta-user value from environment variable .*", |
| 140 }, { |
| 141 » info: "can get manta-user from env variable", |
| 142 » insert: coretesting.Attrs{"manta-user": ""}, |
| 143 » expect: coretesting.Attrs{"manta-user": "tester"}, |
| 144 » envVars: map[string]string{ |
| 145 » » "MANTA_USER": "tester", |
| 146 » }, |
| 147 }, { |
| 148 » info: "can get manta-user from env variable, missing from config", |
| 149 » remove: []string{"manta-user"}, |
| 150 » expect: coretesting.Attrs{"manta-user": "tester"}, |
| 151 » envVars: map[string]string{ |
| 152 » » "MANTA_USER": "tester", |
| 153 » }, |
92 }, { | 154 }, { |
93 info: "manta-key-id is required", | 155 info: "manta-key-id is required", |
94 remove: []string{"manta-key-id"}, | 156 remove: []string{"manta-key-id"}, |
95 » err: "manta-key-id: expected string, got nothing", | 157 » err: ".* cannot get manta-key-id value from environment variable .*", |
96 }, { | 158 }, { |
97 info: "manta-key-id cannot be empty", | 159 info: "manta-key-id cannot be empty", |
98 insert: coretesting.Attrs{"manta-key-id": ""}, | 160 insert: coretesting.Attrs{"manta-key-id": ""}, |
99 » err: "manta-key-id: must not be empty", | 161 » err: ".* cannot get manta-key-id value from environment variable .*", |
100 }, { | 162 }, { |
101 » info: "manta-region is inserted if missing", | 163 » info: "can get manta-key-id from env variable", |
102 » expect: coretesting.Attrs{"manta-region": "us-east"}, | 164 » insert: coretesting.Attrs{"manta-key-id": ""}, |
| 165 » expect: coretesting.Attrs{"manta-key-id": "key"}, |
| 166 » envVars: map[string]string{ |
| 167 » » "MANTA_KEY_ID": "key", |
| 168 » }, |
103 }, { | 169 }, { |
104 » info: "manta-region cannot be empty", | 170 » info: "can get manta-key-id from env variable, missing from config", |
105 » insert: coretesting.Attrs{"manta-region": ""}, | 171 » remove: []string{"manta-key-id"}, |
106 » err: "manta-region: must not be empty", | 172 » expect: coretesting.Attrs{"manta-key-id": "key"}, |
| 173 » envVars: map[string]string{ |
| 174 » » "MANTA_KEY_ID": "key", |
| 175 » }, |
107 }, { | 176 }, { |
108 » info: "manta-region is untouched if present", | 177 » info: "manta-url is inserted if missing", |
109 » insert: coretesting.Attrs{"manta-region": "us-east"}, | 178 » expect: coretesting.Attrs{"manta-url": "https://test.manta.joyent.com"}, |
110 » expect: coretesting.Attrs{"manta-region": "us-east"}, | 179 }, { |
| 180 » info: "manta-url cannot be empty", |
| 181 » insert: coretesting.Attrs{"manta-url": ""}, |
| 182 » err: ".* cannot get manta-url value from environment variable .*", |
| 183 }, { |
| 184 » info: "manta-url is untouched if present", |
| 185 » insert: coretesting.Attrs{"manta-url": "https://test.manta.joyent.com"}, |
| 186 » expect: coretesting.Attrs{"manta-url": "https://test.manta.joyent.com"}, |
| 187 }, { |
| 188 » info: "key-file is inserted if missing", |
| 189 » remove: []string{"key-file"}, |
| 190 » expect: coretesting.Attrs{"key-file": "~/.ssh/id_rsa"}, |
| 191 }, { |
| 192 » info: "can get key-file from env variable", |
| 193 » insert: coretesting.Attrs{"key-file": ""}, |
| 194 » expect: coretesting.Attrs{"key-file": "some-file"}, |
| 195 » envVars: map[string]string{ |
| 196 » » "MANTA_KEY_FILE": "some-file", |
| 197 » }, |
| 198 }, { |
| 199 » info: "can get key-file from env variable, missing from config", |
| 200 » remove: []string{"key-file"}, |
| 201 » expect: coretesting.Attrs{"key-file": "some-file"}, |
| 202 » envVars: map[string]string{ |
| 203 » » "MANTA_KEY_FILE": "some-file", |
| 204 » }, |
| 205 }, { |
| 206 » info: "algorithm is inserted if missing", |
| 207 » expect: coretesting.Attrs{"algorithm": "rsa-sha256"}, |
| 208 }, { |
| 209 » info: "algorithm cannot be empty", |
| 210 » insert: coretesting.Attrs{"algorithm": ""}, |
| 211 » err: ".* algorithm: must not be empty", |
111 }, { | 212 }, { |
112 info: "unknown field is not touched", | 213 info: "unknown field is not touched", |
113 insert: coretesting.Attrs{"unknown-field": 12345}, | 214 insert: coretesting.Attrs{"unknown-field": 12345}, |
114 expect: coretesting.Attrs{"unknown-field": 12345}, | 215 expect: coretesting.Attrs{"unknown-field": 12345}, |
115 }} | 216 }} |
116 | 217 |
117 func (*ConfigSuite) TestNewEnvironConfig(c *gc.C) { | 218 func (*ConfigSuite) TestNewEnvironConfig(c *gc.C) { |
118 for i, test := range newConfigTests { | 219 for i, test := range newConfigTests { |
119 c.Logf("test %d: %s", i, test.info) | 220 c.Logf("test %d: %s", i, test.info) |
| 221 for k, v := range test.envVars { |
| 222 os.Setenv(k, v) |
| 223 } |
120 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) | 224 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) |
121 testConfig := newConfig(c, attrs) | 225 testConfig := newConfig(c, attrs) |
122 environ, err := environs.New(testConfig) | 226 environ, err := environs.New(testConfig) |
123 if test.err == "" { | 227 if test.err == "" { |
124 » » » c.Assert(err, gc.IsNil) | 228 » » » c.Check(err, gc.IsNil) |
125 attrs := environ.Config().AllAttrs() | 229 attrs := environ.Config().AllAttrs() |
126 for field, value := range test.expect { | 230 for field, value := range test.expect { |
127 c.Check(attrs[field], gc.Equals, value) | 231 c.Check(attrs[field], gc.Equals, value) |
128 } | 232 } |
129 } else { | 233 } else { |
130 » » » c.Assert(environ, gc.IsNil) | 234 » » » c.Check(environ, gc.IsNil) |
131 c.Check(err, gc.ErrorMatches, test.err) | 235 c.Check(err, gc.ErrorMatches, test.err) |
132 } | 236 } |
133 } | 237 } |
134 } | 238 } |
135 | 239 |
136 func (*ConfigSuite) TestValidateNewConfig(c *gc.C) { | |
137 for i, test := range newConfigTests { | |
138 c.Logf("test %d: %s", i, test.info) | |
139 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) | |
140 testConfig := newConfig(c, attrs) | |
141 validatedConfig, err := joyent.Provider.Validate(testConfig, nil
) | |
142 if test.err == "" { | |
143 c.Assert(err, gc.IsNil) | |
144 attrs := validatedConfig.AllAttrs() | |
145 for field, value := range test.expect { | |
146 c.Check(attrs[field], gc.Equals, value) | |
147 } | |
148 } else { | |
149 c.Assert(validatedConfig, gc.IsNil) | |
150 c.Check(err, gc.ErrorMatches, "invalid Joyent provider c
onfig: "+test.err) | |
151 } | |
152 } | |
153 } | |
154 | |
155 func (*ConfigSuite) TestValidateOldConfig(c *gc.C) { | |
156 knownGoodConfig := newConfig(c, validAttrs()) | |
157 for i, test := range newConfigTests { | |
158 c.Logf("test %d: %s", i, test.info) | |
159 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) | |
160 testConfig := newConfig(c, attrs) | |
161 validatedConfig, err := joyent.Provider.Validate(knownGoodConfig
, testConfig) | |
162 if test.err == "" { | |
163 c.Assert(err, gc.IsNil) | |
164 attrs := validatedConfig.AllAttrs() | |
165 for field, value := range validAttrs() { | |
166 c.Check(attrs[field], gc.Equals, value) | |
167 } | |
168 } else { | |
169 c.Assert(validatedConfig, gc.IsNil) | |
170 c.Check(err, gc.ErrorMatches, "original Joyent provider
config is invalid: "+test.err) | |
171 } | |
172 } | |
173 } | |
174 | |
175 var changeConfigTests = []struct { | 240 var changeConfigTests = []struct { |
176 info string | 241 info string |
177 insert coretesting.Attrs | 242 insert coretesting.Attrs |
178 remove []string | 243 remove []string |
179 expect coretesting.Attrs | 244 expect coretesting.Attrs |
180 err string | 245 err string |
181 }{{ | 246 }{{ |
182 info: "no change, no error", | 247 info: "no change, no error", |
183 expect: validAttrs(), | 248 expect: validAttrs(), |
184 }, { | 249 }, { |
185 info: "can change sdc-user", | 250 info: "can change sdc-user", |
186 insert: coretesting.Attrs{"sdc-user": "joyent_user"}, | 251 insert: coretesting.Attrs{"sdc-user": "joyent_user"}, |
187 expect: coretesting.Attrs{"sdc-user": "joyent_user"}, | 252 expect: coretesting.Attrs{"sdc-user": "joyent_user"}, |
188 }, { | 253 }, { |
189 info: "can change sdc-key-id", | 254 info: "can change sdc-key-id", |
190 » insert: coretesting.Attrs{"sdc-key-id": "11:c4:b6:c0:a3:24:22:96:a8:1f:0
7:53:3f:8e:14:7a"}, | 255 » insert: coretesting.Attrs{"sdc-key-id": "ff:ee:dd:cc:bb:aa:99:88:77:66:5
5:44:33:22:11:00"}, |
191 » expect: coretesting.Attrs{"sdc-key-id": "11:c4:b6:c0:a3:24:22:96:a8:1f:0
7:53:3f:8e:14:7a"}, | 256 » expect: coretesting.Attrs{"sdc-key-id": "ff:ee:dd:cc:bb:aa:99:88:77:66:5
5:44:33:22:11:00"}, |
192 }, { | 257 }, { |
193 » info: "can change sdc-region", | 258 » info: "can change sdc-url", |
194 » insert: coretesting.Attrs{"sdc-region": "us-west-1"}, | 259 » insert: coretesting.Attrs{"sdc-url": "https://test.api.joyentcloud.com"}
, |
195 » expect: coretesting.Attrs{"sdc-region": "us-west-1"}, | 260 » expect: coretesting.Attrs{"sdc-url": "https://test.api.joyentcloud.com"}
, |
196 }, { | 261 }, { |
197 info: "can change manta-user", | 262 info: "can change manta-user", |
198 insert: coretesting.Attrs{"manta-user": "manta_user"}, | 263 insert: coretesting.Attrs{"manta-user": "manta_user"}, |
199 expect: coretesting.Attrs{"manta-user": "manta_user"}, | 264 expect: coretesting.Attrs{"manta-user": "manta_user"}, |
200 }, { | 265 }, { |
201 info: "can change manta-key-id", | 266 info: "can change manta-key-id", |
202 » insert: coretesting.Attrs{"manta-key-id": "11:c4:b6:c0:a3:24:22:96:a8:1f
:07:53:3f:8e:14:7a"}, | 267 » insert: coretesting.Attrs{"manta-key-id": "ff:ee:dd:cc:bb:aa:99:88:77:66
:55:44:33:22:11:00"}, |
203 » expect: coretesting.Attrs{"manta-key-id": "11:c4:b6:c0:a3:24:22:96:a8:1f
:07:53:3f:8e:14:7a"}, | 268 » expect: coretesting.Attrs{"manta-key-id": "ff:ee:dd:cc:bb:aa:99:88:77:66
:55:44:33:22:11:00"}, |
204 }, { | 269 }, { |
205 » info: "can change manta-region", | 270 » info: "can change manta-url", |
206 » insert: coretesting.Attrs{"manta-region": "us-east"}, | 271 » insert: coretesting.Attrs{"manta-url": "https://test.manta.joyent.com"}, |
207 » expect: coretesting.Attrs{"manta-region": "us-east"}, | 272 » expect: coretesting.Attrs{"manta-url": "https://test.manta.joyent.com"}, |
208 }, { | 273 }, { |
209 info: "can insert unknown field", | 274 info: "can insert unknown field", |
210 insert: coretesting.Attrs{"unknown": "ignoti"}, | 275 insert: coretesting.Attrs{"unknown": "ignoti"}, |
211 expect: coretesting.Attrs{"unknown": "ignoti"}, | 276 expect: coretesting.Attrs{"unknown": "ignoti"}, |
212 }} | 277 }} |
213 | 278 |
214 func (s *ConfigSuite) TestValidateChange(c *gc.C) { | 279 func (s *ConfigSuite) TestValidateChange(c *gc.C) { |
215 baseConfig := newConfig(c, validAttrs()) | 280 baseConfig := newConfig(c, validAttrs()) |
216 for i, test := range changeConfigTests { | 281 for i, test := range changeConfigTests { |
217 c.Logf("test %d: %s", i, test.info) | 282 c.Logf("test %d: %s", i, test.info) |
218 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) | 283 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) |
219 testConfig := newConfig(c, attrs) | 284 testConfig := newConfig(c, attrs) |
220 » » validatedConfig, err := joyent.Provider.Validate(testConfig, bas
eConfig) | 285 » » validatedConfig, err := jp.Provider.Validate(testConfig, baseCon
fig) |
221 if test.err == "" { | 286 if test.err == "" { |
222 » » » c.Assert(err, gc.IsNil) | 287 » » » c.Check(err, gc.IsNil) |
223 attrs := validatedConfig.AllAttrs() | 288 attrs := validatedConfig.AllAttrs() |
224 for field, value := range test.expect { | 289 for field, value := range test.expect { |
225 c.Check(attrs[field], gc.Equals, value) | 290 c.Check(attrs[field], gc.Equals, value) |
226 } | 291 } |
227 } else { | 292 } else { |
228 » » » c.Assert(validatedConfig, gc.IsNil) | 293 » » » c.Check(validatedConfig, gc.IsNil) |
229 c.Check(err, gc.ErrorMatches, "invalid config change: "+
test.err) | 294 c.Check(err, gc.ErrorMatches, "invalid config change: "+
test.err) |
230 } | 295 } |
231 } | 296 } |
232 } | 297 } |
233 | 298 |
234 func (s *ConfigSuite) TestSetConfig(c *gc.C) { | 299 func (s *ConfigSuite) TestSetConfig(c *gc.C) { |
235 baseConfig := newConfig(c, validAttrs()) | 300 baseConfig := newConfig(c, validAttrs()) |
236 for i, test := range changeConfigTests { | 301 for i, test := range changeConfigTests { |
237 c.Logf("test %d: %s", i, test.info) | 302 c.Logf("test %d: %s", i, test.info) |
238 environ, err := environs.New(baseConfig) | 303 environ, err := environs.New(baseConfig) |
239 c.Assert(err, gc.IsNil) | 304 c.Assert(err, gc.IsNil) |
240 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) | 305 attrs := validAttrs().Merge(test.insert).Delete(test.remove...) |
241 testConfig := newConfig(c, attrs) | 306 testConfig := newConfig(c, attrs) |
242 err = environ.SetConfig(testConfig) | 307 err = environ.SetConfig(testConfig) |
243 newAttrs := environ.Config().AllAttrs() | 308 newAttrs := environ.Config().AllAttrs() |
244 if test.err == "" { | 309 if test.err == "" { |
245 » » » c.Assert(err, gc.IsNil) | 310 » » » c.Check(err, gc.IsNil) |
246 for field, value := range test.expect { | 311 for field, value := range test.expect { |
247 c.Check(newAttrs[field], gc.Equals, value) | 312 c.Check(newAttrs[field], gc.Equals, value) |
248 } | 313 } |
249 } else { | 314 } else { |
250 c.Check(err, gc.ErrorMatches, test.err) | 315 c.Check(err, gc.ErrorMatches, test.err) |
251 for field, value := range baseConfig.UnknownAttrs() { | 316 for field, value := range baseConfig.UnknownAttrs() { |
252 c.Check(newAttrs[field], gc.Equals, value) | 317 c.Check(newAttrs[field], gc.Equals, value) |
253 } | 318 } |
254 } | 319 } |
255 } | 320 } |
256 } | 321 } |
257 | 322 |
| 323 func validPrepareAttrs() coretesting.Attrs { |
| 324 return validAttrs().Delete("private-key") |
| 325 } |
| 326 |
258 var prepareConfigTests = []struct { | 327 var prepareConfigTests = []struct { |
259 info string | 328 info string |
260 insert coretesting.Attrs | 329 insert coretesting.Attrs |
261 remove []string | 330 remove []string |
262 expect coretesting.Attrs | 331 expect coretesting.Attrs |
263 err string | 332 err string |
264 }{{ | 333 }{{ |
265 info: "All value provided, nothig to do", | 334 info: "All value provided, nothig to do", |
266 » expect: validAttrs(), | 335 » expect: validPrepareAttrs(), |
267 }, { | 336 }, { |
268 » info: "can get sdc-user from env variable", | 337 » info: "private key is loaded from key file", |
269 » insert: coretesting.Attrs{"sdc-user": ""}, | 338 » insert: coretesting.Attrs{"key-file": fmt.Sprintf("~/.ssh/%s", testKeyFi
leName)}, |
270 » expect: coretesting.Attrs{"sdc-user": "tester"}, | 339 » expect: coretesting.Attrs{"private-key": testPrivateKey}, |
271 }, { | |
272 » info: "can get sdc-key-id from env variable", | |
273 » insert: coretesting.Attrs{"sdc-key-id": ""}, | |
274 » expect: coretesting.Attrs{"sdc-key-id": "11:c4:b6:c0:a3:24:22:96:a8:1f:0
7:53:3f:8e:14:7a"}, | |
275 }, { | |
276 » info: "can get manta-user from env variable", | |
277 » insert: coretesting.Attrs{"manta-user": ""}, | |
278 » expect: coretesting.Attrs{"manta-user": "tester"}, | |
279 }, { | |
280 » info: "can get manta-key-id from env variable", | |
281 » insert: coretesting.Attrs{"manta-key-id": ""}, | |
282 » expect: coretesting.Attrs{"manta-key-id": "11:c4:b6:c0:a3:24:22:96:a8:1f
:07:53:3f:8e:14:7a"}, | |
283 }} | 340 }} |
284 | 341 |
285 func (s *ConfigSuite) TestPrepare(c *gc.C) { | 342 func (s *ConfigSuite) TestPrepare(c *gc.C) { |
| 343 ctx := coretesting.Context(c) |
286 for i, test := range prepareConfigTests { | 344 for i, test := range prepareConfigTests { |
287 c.Logf("test %d: %s", i, test.info) | 345 c.Logf("test %d: %s", i, test.info) |
288 » » attrs := validAttrs().Merge(test.insert).Delete(test.remove...) | 346 » » attrs := validPrepareAttrs().Merge(test.insert).Delete(test.remo
ve...) |
289 testConfig := newConfig(c, attrs) | 347 testConfig := newConfig(c, attrs) |
290 » » preparedConfig, err := joyent.Provider.Prepare(coretesting.Conte
xt(c), testConfig) | 348 » » preparedConfig, err := jp.Provider.Prepare(ctx, testConfig) |
291 if test.err == "" { | 349 if test.err == "" { |
292 » » » c.Assert(err, gc.IsNil) | 350 » » » c.Check(err, gc.IsNil) |
293 attrs := preparedConfig.Config().AllAttrs() | 351 attrs := preparedConfig.Config().AllAttrs() |
294 for field, value := range test.expect { | 352 for field, value := range test.expect { |
295 c.Check(attrs[field], gc.Equals, value) | 353 c.Check(attrs[field], gc.Equals, value) |
296 } | 354 } |
297 } else { | 355 } else { |
298 » » » c.Assert(preparedConfig, gc.IsNil) | 356 » » » c.Check(preparedConfig, gc.IsNil) |
299 c.Check(err, gc.ErrorMatches, "invalid prepare config: "
+test.err) | 357 c.Check(err, gc.ErrorMatches, "invalid prepare config: "
+test.err) |
300 } | 358 } |
301 } | 359 } |
302 } | 360 } |
OLD | NEW |