func (s *varsSuite) TestBlankJujuHomeEnvVar(c *gc.C) { s.PatchEnvironment(osenv.JujuHomeEnvKey, "") if runtime.GOOS == "windows" { s.PatchEnvironment("APPDATA", `P:\foobar`) } else { s.PatchEnvironment("HOME", "/foobar") } c.Assert(osenv.JujuHomeDir(), gc.Not(gc.Equals), "") if runtime.GOOS == "windows" { c.Assert(osenv.JujuHomeDir(), gc.Equals, osenv.JujuHomeWin()) } else { c.Assert(osenv.JujuHomeDir(), gc.Equals, osenv.JujuHomeLinux()) } }
func setCacheDir() { jujuHome := osenv.JujuHomeDir() if jujuHome == "" { log.Fatal("cannot determine juju home, required environment variables are not set") } osenv.SetJujuHome(jujuHome) charmrepo.CacheDir = osenv.JujuHomePath("charmcache") }
// InitJujuHome initializes the charm cache, environs/config and utils/ssh packages // to use default paths based on the $JUJU_HOME or $HOME environment variables. // This function should be called before running a Juju CLI command. func InitJujuHome() error { jujuHome := osenv.JujuHomeDir() if jujuHome == "" { return errors.New("cannot determine juju home, required model variables are not set") } osenv.SetJujuHome(jujuHome) charmrepo.CacheDir = osenv.JujuHomePath("charmcache") if err := ssh.LoadClientKeys(osenv.JujuHomePath("ssh")); err != nil { return errors.Annotate(err, "cannot load ssh client keys") } return nil }
// InitJujuHome initializes the charm cache, environs/config and utils/ssh packages // to use default paths based on the $JUJU_HOME or $HOME environment variables. // This function should be called before running a Juju CLI command. func InitJujuHome() error { jujuHome := osenv.JujuHomeDir() if jujuHome == "" { return stderrors.New( "cannot determine juju home, required environment variables are not set") } osenv.SetJujuHome(jujuHome) charmrepo.CacheDir = osenv.JujuHomePath("charmcache") if err := ssh.LoadClientKeys(osenv.JujuHomePath("ssh")); err != nil { return fmt.Errorf("cannot load ssh client keys: %v", err) } return nil }
func (s *varsSuite) TestJujuHomeEnvVar(c *gc.C) { path := "/foo/bar/baz" s.PatchEnvironment(osenv.JujuHomeEnvKey, path) c.Assert(osenv.JujuHomeDir(), gc.Equals, path) }