func (s *TestingEnvironSuite) TestFakeHomeRestoresEnvironment(c *C) { fake := testing.MakeEmptyFakeHome(c) fake.Restore() c.Assert(os.Getenv("HOME"), Equals, "/home/eric") c.Assert(os.Getenv("JUJU_HOME"), Equals, "/home/eric/juju") c.Assert(config.JujuHome(), Equals, "/home/eric/juju") }
func (s *InitJujuHomeSuite) TestHome(c *C) { os.Setenv("JUJU_HOME", "") os.Setenv("HOME", "/my/home/") err := juju.InitJujuHome() c.Assert(err, IsNil) c.Assert(config.JujuHome(), Equals, "/my/home/.juju") }
func (s *JujuHomeSuite) TestErrorHome(c *C) { // Invalid juju home leads to panic when retrieving. f := func() { _ = config.JujuHome() } c.Assert(f, PanicMatches, "juju home hasn't been initialized") f = func() { _ = config.JujuHomePath("environments.yaml") } c.Assert(f, PanicMatches, "juju home hasn't been initialized") }
func badrun(c *gc.C, exit int, args ...string) string { localArgs := append([]string{"-test.run", "TestRunMain", "-run-main", "--", "juju"}, args...) ps := exec.Command(os.Args[0], localArgs...) ps.Env = append(os.Environ(), "JUJU_HOME="+config.JujuHome()) output, err := ps.CombinedOutput() if exit != 0 { c.Assert(err, gc.ErrorMatches, fmt.Sprintf("exit status %d", exit)) } return string(output) }
// WriteCertAndKey writes the provided certificate and key // to the juju home directory, creating it if necessary, func WriteCertAndKey(name string, cert, key []byte) error { // If the juju home directory doesn't exist, create it. jujuHome := config.JujuHome() if err := os.MkdirAll(jujuHome, 0775); err != nil { return err } path := filepath.Join(jujuHome, name) if err := ioutil.WriteFile(path+"-cert.pem", cert, 0644); err != nil { return err } return ioutil.WriteFile(path+"-private-key.pem", key, 0600) }
func (c *ImageMetadataCommand) Run(context *cmd.Context) error { out := context.Stdout im := imagemetadata.ImageMetadata{ Id: c.ImageId, Arch: c.Arch, } cloudSpec := imagemetadata.CloudSpec{ Region: c.Region, Endpoint: c.Endpoint, } files, err := imagemetadata.Boilerplate(c.Name, c.Series, &im, &cloudSpec) if err != nil { return fmt.Errorf("boilerplate image metadata files could not be created: %v", err) } fmt.Fprintf( out, "Boilerplate image metadata files %q have been written to %s.\n", strings.Join(files, ", "), config.JujuHome()) fmt.Fprintf(out, `Copy the files to the path "streams/v1" in your cloud's public bucket.`) fmt.Fprintln(out, "") return nil }
func (s *JujuHomeSuite) TestStandardHome(c *C) { testJujuHome := c.MkDir() defer config.SetJujuHome(config.SetJujuHome(testJujuHome)) c.Assert(config.JujuHome(), Equals, testJujuHome) }
func (s *TestingEnvironSuite) TestFakeHomeSetsConfigJujuHome(c *C) { _ = testing.MakeEmptyFakeHome(c) expected := filepath.Join(os.Getenv("HOME"), ".juju") c.Assert(config.JujuHome(), Equals, expected) }
func (s *TestingEnvironSuite) TestFakeHomeReplacesEnvironment(c *C) { _ = testing.MakeEmptyFakeHome(c) c.Assert(os.Getenv("HOME"), Not(Equals), "/home/eric") c.Assert(os.Getenv("JUJU_HOME"), Equals, "") c.Assert(config.JujuHome(), Not(Equals), "/home/eric/juju") }
func getCurrentEnvironmentFilePath() string { return filepath.Join(config.JujuHome(), CurrentEnvironmentFilename) }
func MakeEmptyFakeHome(c *C) *FakeHome { fake := MakeEmptyFakeHomeWithoutJuju(c) err := os.Mkdir(config.JujuHome(), 0700) c.Assert(err, IsNil) return fake }