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

Delta Between Two Patch Sets: provider/local/config_test.go

Issue 13355044: environs/config: more restrictive New
Left Patch Set: environs/config: more restrictive New Created 11 years, 7 months ago
Right Patch Set: environs/config: more restrictive New Created 11 years, 7 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « provider/ec2/local_test.go ('k') | provider/local/environ_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 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 local_test 4 package local_test
5 5
6 import ( 6 import (
7 "os" 7 "os"
8 "path/filepath" 8 "path/filepath"
9 "runtime" 9 "runtime"
10 "syscall" 10 "syscall"
11 11
12 gc "launchpad.net/gocheck" 12 gc "launchpad.net/gocheck"
13 13
14 "launchpad.net/juju-core/environs/config" 14 "launchpad.net/juju-core/environs/config"
15 "launchpad.net/juju-core/juju/osenv"
15 "launchpad.net/juju-core/provider" 16 "launchpad.net/juju-core/provider"
16 "launchpad.net/juju-core/provider/local" 17 "launchpad.net/juju-core/provider/local"
17 "launchpad.net/juju-core/testing" 18 "launchpad.net/juju-core/testing"
18 ) 19 )
19 20
20 type configSuite struct { 21 type configSuite struct {
21 baseProviderSuite 22 baseProviderSuite
22 oldUser string 23 oldUser string
23 } 24 }
24 25
(...skipping 24 matching lines...) Expand all
49 c.Assert(err, gc.IsNil) 50 c.Assert(err, gc.IsNil)
50 return testConfig 51 return testConfig
51 } 52 }
52 53
53 func (s *configSuite) TestValidateConfig(c *gc.C) { 54 func (s *configSuite) TestValidateConfig(c *gc.C) {
54 testConfig := minimalConfig(c) 55 testConfig := minimalConfig(c)
55 56
56 valid, err := local.Provider.Validate(testConfig, nil) 57 valid, err := local.Provider.Validate(testConfig, nil)
57 c.Assert(err, gc.IsNil) 58 c.Assert(err, gc.IsNil)
58 59
59 » expectedRootDir := filepath.Join(os.Getenv("HOME"), ".juju", "test") 60 » expectedRootDir := filepath.Join(osenv.Home(), ".juju", "test")
60 unknownAttrs := valid.UnknownAttrs() 61 unknownAttrs := valid.UnknownAttrs()
61 c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir) 62 c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir)
62 } 63 }
63 64
64 func (s *configSuite) TestValidateConfigWithRootDir(c *gc.C) { 65 func (s *configSuite) TestValidateConfigWithRootDir(c *gc.C) {
65 values := minimalConfigValues() 66 values := minimalConfigValues()
66 root := c.MkDir() 67 root := c.MkDir()
67 values["root-dir"] = root 68 values["root-dir"] = root
68 testConfig, err := config.New(config.NoDefaults, values) 69 testConfig, err := config.New(config.NoDefaults, values)
69 c.Assert(err, gc.IsNil) 70 c.Assert(err, gc.IsNil)
70 71
71 valid, err := local.Provider.Validate(testConfig, nil) 72 valid, err := local.Provider.Validate(testConfig, nil)
72 c.Assert(err, gc.IsNil) 73 c.Assert(err, gc.IsNil)
73 unknownAttrs := valid.UnknownAttrs() 74 unknownAttrs := valid.UnknownAttrs()
74 c.Assert(unknownAttrs["root-dir"], gc.Equals, root) 75 c.Assert(unknownAttrs["root-dir"], gc.Equals, root)
75 } 76 }
76 77
77 func (s *configSuite) TestValidateConfigWithTildeInRootDir(c *gc.C) { 78 func (s *configSuite) TestValidateConfigWithTildeInRootDir(c *gc.C) {
78 values := minimalConfigValues() 79 values := minimalConfigValues()
79 values["root-dir"] = "~/.juju/foo" 80 values["root-dir"] = "~/.juju/foo"
80 testConfig, err := config.New(config.NoDefaults, values) 81 testConfig, err := config.New(config.NoDefaults, values)
81 c.Assert(err, gc.IsNil) 82 c.Assert(err, gc.IsNil)
82 83
83 valid, err := local.Provider.Validate(testConfig, nil) 84 valid, err := local.Provider.Validate(testConfig, nil)
84 c.Assert(err, gc.IsNil) 85 c.Assert(err, gc.IsNil)
85 86
86 » expectedRootDir := filepath.Join(os.Getenv("HOME"), ".juju", "foo") 87 » expectedRootDir := filepath.Join(osenv.Home(), ".juju", "foo")
87 unknownAttrs := valid.UnknownAttrs() 88 unknownAttrs := valid.UnknownAttrs()
88 c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir) 89 c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir)
89 } 90 }
90 91
91 func (s *configSuite) TestNamespace(c *gc.C) { 92 func (s *configSuite) TestNamespace(c *gc.C) {
92 testConfig := minimalConfig(c) 93 testConfig := minimalConfig(c)
93 c.Assert(local.ConfigNamespace(testConfig), gc.Equals, "tester-test") 94 c.Assert(local.ConfigNamespace(testConfig), gc.Equals, "tester-test")
94 } 95 }
95 96
96 func (s *configSuite) TestNamespaceRootNoSudo(c *gc.C) { 97 func (s *configSuite) TestNamespaceRootNoSudo(c *gc.C) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 c.Assert(err, gc.IsNil) 206 c.Assert(err, gc.IsNil)
206 // Check that the dirs are owned by the UID/GID set above.. 207 // Check that the dirs are owned by the UID/GID set above..
207 for _, dir := range local.CheckDirs(c, testConfig) { 208 for _, dir := range local.CheckDirs(c, testConfig) {
208 info, err := os.Stat(dir) 209 info, err := os.Stat(dir)
209 c.Assert(err, gc.IsNil) 210 c.Assert(err, gc.IsNil)
210 // This call is linux specific, but then so is sudo 211 // This call is linux specific, but then so is sudo
211 c.Assert(info.Sys().(*syscall.Stat_t).Uid, gc.Equals, uint32(100 0)) 212 c.Assert(info.Sys().(*syscall.Stat_t).Uid, gc.Equals, uint32(100 0))
212 c.Assert(info.Sys().(*syscall.Stat_t).Gid, gc.Equals, uint32(100 0)) 213 c.Assert(info.Sys().(*syscall.Stat_t).Gid, gc.Equals, uint32(100 0))
213 } 214 }
214 } 215 }
LEFTRIGHT

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