Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(80)

Side by Side Diff: provider/ec2/config_test.go

Issue 13421050: environs: add Environs.Config method
Patch Set: environs: add Environs.Config method Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « environs/open_test.go ('k') | provider/openstack/config_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ec2 4 package ec2
5 5
6 // TODO: Clean this up so it matches environs/openstack/config_test.go. 6 // TODO: Clean this up so it matches environs/openstack/config_test.go.
7 7
8 import ( 8 import (
9 "io/ioutil" 9 "io/ioutil"
10 "os" 10 "os"
11 "path/filepath" 11 "path/filepath"
12 "strings" 12 "strings"
13 13
14 "launchpad.net/goamz/aws" 14 "launchpad.net/goamz/aws"
15 gc "launchpad.net/gocheck" 15 gc "launchpad.net/gocheck"
16 "launchpad.net/goyaml"
17 16
18 "launchpad.net/juju-core/environs" 17 "launchpad.net/juju-core/environs"
19 "launchpad.net/juju-core/environs/config" 18 "launchpad.net/juju-core/environs/config"
20 "launchpad.net/juju-core/juju/osenv" 19 "launchpad.net/juju-core/juju/osenv"
21 "launchpad.net/juju-core/testing" 20 "launchpad.net/juju-core/testing"
22 ) 21 )
23 22
24 // Use local suite since this file lives in the ec2 package 23 // Use local suite since this file lives in the ec2 package
25 // for testing internals. 24 // for testing internals.
26 type ConfigSuite struct { 25 type ConfigSuite struct {
27 testing.LoggingSuite 26 testing.LoggingSuite
28 savedHome, savedAccessKey, savedSecretKey string 27 savedHome, savedAccessKey, savedSecretKey string
29 } 28 }
30 29
31 var _ = gc.Suite(&ConfigSuite{}) 30 var _ = gc.Suite(&ConfigSuite{})
32 31
33 var configTestRegion = aws.Region{ 32 var configTestRegion = aws.Region{
34 Name: "configtest", 33 Name: "configtest",
35 EC2Endpoint: "testregion.nowhere:1234", 34 EC2Endpoint: "testregion.nowhere:1234",
36 } 35 }
37 36
38 var testAuth = aws.Auth{"gopher", "long teeth"} 37 var testAuth = aws.Auth{"gopher", "long teeth"}
39 38
40 // configTest specifies a config parsing test, checking that env when 39 // configTest specifies a config parsing test, checking that env when
41 // parsed as the ec2 section of a config file matches baseConfigResult 40 // parsed as the ec2 section of a config file matches baseConfigResult
42 // when mutated by the mutate function, or that the parse matches the 41 // when mutated by the mutate function, or that the parse matches the
43 // given error. 42 // given error.
44 type configTest struct { 43 type configTest struct {
45 » config attrs 44 » config map[string]interface{}
46 » change attrs 45 » change map[string]interface{}
47 » expect attrs 46 » expect map[string]interface{}
48 region string 47 region string
49 cbucket string 48 cbucket string
50 pbucket string 49 pbucket string
51 pbucketRegion string 50 pbucketRegion string
52 accessKey string 51 accessKey string
53 secretKey string 52 secretKey string
54 firewallMode string 53 firewallMode string
55 err string 54 err string
56 } 55 }
57 56
58 type attrs map[string]interface{} 57 type attrs map[string]interface{}
59 58
60 func (t configTest) check(c *gc.C) { 59 func (t configTest) check(c *gc.C) {
61 » envs := attrs{ 60 » attrs := testing.FakeConfig().Merge(testing.Attrs{
62 » » "environments": attrs{ 61 » » "type": "ec2",
63 » » » "testenv": attrs{ 62 » » "control-bucket": "x",
64 » » » » "type": "ec2", 63 » }).Merge(t.config)
65 » » » » "ca-cert": testing.CACert, 64 » cfg, err := config.New(config.NoDefaults, attrs)
66 » » » » "ca-private-key": testing.CAKey,
67 » » » },
68 » » },
69 » }
70 » testenv := envs["environments"].(attrs)["testenv"].(attrs)
71 » for k, v := range t.config {
72 » » testenv[k] = v
73 » }
74 » if _, ok := testenv["control-bucket"]; !ok {
75 » » testenv["control-bucket"] = "x"
76 » }
77 » data, err := goyaml.Marshal(envs)
78 c.Assert(err, gc.IsNil) 65 c.Assert(err, gc.IsNil)
79 66 » e, err := environs.New(cfg)
80 » es, err := environs.ReadEnvironsBytes(data)
81 » c.Check(err, gc.IsNil)
82
83 » e, err := es.Open("testenv")
84 if t.change != nil { 67 if t.change != nil {
85 c.Assert(err, gc.IsNil) 68 c.Assert(err, gc.IsNil)
86 69
87 // Testing a change in configuration. 70 // Testing a change in configuration.
88 var old, changed, valid *config.Config 71 var old, changed, valid *config.Config
89 ec2env := e.(*environ) 72 ec2env := e.(*environ)
90 old = ec2env.ecfg().Config 73 old = ec2env.ecfg().Config
91 changed, err = old.Apply(t.change) 74 changed, err = old.Apply(t.change)
92 c.Assert(err, gc.IsNil) 75 c.Assert(err, gc.IsNil)
93 76
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 err: ".*environment has no access-key or secret-key", 236 err: ".*environment has no access-key or secret-key",
254 }, { 237 }, {
255 config: attrs{ 238 config: attrs{
256 "admin-secret": "Futumpsh", 239 "admin-secret": "Futumpsh",
257 }, 240 },
258 }, { 241 }, {
259 config: attrs{}, 242 config: attrs{},
260 firewallMode: config.FwInstance, 243 firewallMode: config.FwInstance,
261 }, { 244 }, {
262 config: attrs{ 245 config: attrs{
263 "firewall-mode": "",
264 },
265 firewallMode: config.FwInstance,
266 }, {
267 config: attrs{
268 "firewall-mode": "instance", 246 "firewall-mode": "instance",
269 }, 247 },
270 firewallMode: config.FwInstance, 248 firewallMode: config.FwInstance,
271 }, { 249 }, {
272 config: attrs{ 250 config: attrs{
273 "firewall-mode": "global", 251 "firewall-mode": "global",
274 }, 252 },
275 firewallMode: config.FwGlobal, 253 firewallMode: config.FwGlobal,
276 }, { 254 }, {
277 config: attrs{ 255 config: attrs{
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 func (s *ConfigSuite) TestMissingAuth(c *gc.C) { 319 func (s *ConfigSuite) TestMissingAuth(c *gc.C) {
342 os.Setenv("AWS_ACCESS_KEY_ID", "") 320 os.Setenv("AWS_ACCESS_KEY_ID", "")
343 os.Setenv("AWS_SECRET_ACCESS_KEY", "") 321 os.Setenv("AWS_SECRET_ACCESS_KEY", "")
344 // Since r37 goamz uses these as fallbacks, so unset them too. 322 // Since r37 goamz uses these as fallbacks, so unset them too.
345 os.Setenv("EC2_ACCESS_KEY", "") 323 os.Setenv("EC2_ACCESS_KEY", "")
346 os.Setenv("EC2_SECRET_KEY", "") 324 os.Setenv("EC2_SECRET_KEY", "")
347 test := configTests[0] 325 test := configTests[0]
348 test.err = "environment has no access-key or secret-key" 326 test.err = "environment has no access-key or secret-key"
349 test.check(c) 327 test.check(c)
350 } 328 }
OLDNEW
« no previous file with comments | « environs/open_test.go ('k') | provider/openstack/config_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b