14
// EnvironConfig returns a default environment configuration suitable for
16
func EnvironConfig(c *C) *config.Config {
17
cfg, err := config.New(map[string]interface{}{
20
"default-series": "test-series",
21
"authorized-keys": "test-keys",
22
"agent-version": "9.9.9.9",
11
30
const SampleEnvName = "erewhemos"
12
31
const EnvDefault = "default:\n " + SampleEnvName + "\n"
56
82
func MakeFakeHomeNoEnvironments(c *C, certNames ...string) *FakeHome {
57
83
fake := MakeEmptyFakeHome(c)
58
err := os.Mkdir(config.JujuHome(), 0755)
61
85
for _, name := range certNames {
62
86
err := ioutil.WriteFile(config.JujuHomePath(name+"-cert.pem"), []byte(CACert), 0600)
65
89
c.Assert(err, IsNil)
68
err = os.Mkdir(HomePath(".ssh"), 0777)
92
err := os.Mkdir(HomePath(".ssh"), 0777)
69
93
c.Assert(err, IsNil)
70
94
err = ioutil.WriteFile(HomePath(".ssh", "id_rsa.pub"), []byte("auth key\n"), 0666)
71
95
c.Assert(err, IsNil)
93
117
func MakeEmptyFakeHome(c *C) *FakeHome {
94
oldHome := os.Getenv("HOME")
118
fake := MakeEmptyFakeHomeWithoutJuju(c)
119
err := os.Mkdir(config.JujuHome(), 0700)
124
func MakeEmptyFakeHomeWithoutJuju(c *C) *FakeHome {
125
oldHomeEnv := os.Getenv("HOME")
126
oldJujuHomeEnv := os.Getenv("JUJU_HOME")
127
oldJujuEnv := os.Getenv("JUJU_ENV")
95
128
fakeHome := c.MkDir()
96
129
os.Setenv("HOME", fakeHome)
97
oldJujuHome := config.SetJujuHome(filepath.Join(fakeHome, ".juju"))
98
return &FakeHome{oldHome, oldJujuHome}
130
os.Setenv("JUJU_HOME", "")
131
os.Setenv("JUJU_ENV", "")
132
jujuHome := filepath.Join(fakeHome, ".juju")
133
oldJujuHome := config.SetJujuHome(jujuHome)
135
oldHomeEnv: oldHomeEnv,
136
oldJujuEnv: oldJujuEnv,
137
oldJujuHomeEnv: oldJujuHomeEnv,
138
oldJujuHome: oldJujuHome,
101
143
func HomePath(names ...string) string {
106
148
func (h *FakeHome) Restore() {
107
149
config.SetJujuHome(h.oldJujuHome)
108
os.Setenv("HOME", h.oldHome)
150
os.Setenv("JUJU_ENV", h.oldJujuEnv)
151
os.Setenv("JUJU_HOME", h.oldJujuHomeEnv)
152
os.Setenv("HOME", h.oldHomeEnv)
155
func (h *FakeHome) AddFiles(c *C, files []TestFile) {
156
for _, f := range files {
157
path := HomePath(f.Name)
158
err := os.MkdirAll(filepath.Dir(path), 0700)
160
err = ioutil.WriteFile(path, []byte(f.Data), 0666)
162
h.files = append(h.files, f)
166
// FileContents returns the test file contents for the
167
// given specified path (which may be relative, so
168
// we compare with the base filename only).
169
func (h *FakeHome) FileContents(c *C, path string) string {
170
for _, f := range h.files {
171
if filepath.Base(f.Name) == filepath.Base(path) {
175
c.Fatalf("path attribute holds unknown test file: %q", path)
179
// FileExists returns if the given relative file path exists
181
func (h *FakeHome) FileExists(path string) bool {
182
for _, f := range h.files {
190
func MakeFakeHomeWithFiles(c *C, files []TestFile) *FakeHome {
191
fake := MakeEmptyFakeHome(c)
192
fake.AddFiles(c, files)
111
196
func MakeSampleHome(c *C) *FakeHome {