本文整理汇总了Golang中github.com/juju/juju/juju/osenv.SetJujuHome函数的典型用法代码示例。如果您正苦于以下问题:Golang SetJujuHome函数的具体用法?Golang SetJujuHome怎么用?Golang SetJujuHome使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetJujuHome函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHelpCommands
func (s *MainSuite) TestHelpCommands(c *gc.C) {
defer osenv.SetJujuHome(osenv.SetJujuHome(c.MkDir()))
// Check that we have correctly registered all the commands
// by checking the help output.
// First check default commands, and then check commands that are
// activated by feature flags.
// Here we can add feature flags for any commands we want to hide by default.
devFeatures := []string{}
// remove features behind dev_flag for the first test
// since they are not enabled.
cmdSet := set.NewStrings(commandNames...)
for _, feature := range devFeatures {
cmdSet.Remove(feature)
}
// 1. Default Commands. Disable all features.
setFeatureFlags("")
// Use sorted values here so we can better see what is wrong.
registered := getHelpCommandNames(c)
unknown := registered.Difference(cmdSet)
c.Assert(unknown, jc.DeepEquals, set.NewStrings())
missing := cmdSet.Difference(registered)
c.Assert(missing, jc.DeepEquals, set.NewStrings())
// 2. Enable development features, and test again.
setFeatureFlags(strings.Join(devFeatures, ","))
registered = getHelpCommandNames(c)
unknown = registered.Difference(cmdSet)
c.Assert(unknown, jc.DeepEquals, set.NewStrings())
missing = cmdSet.Difference(registered)
c.Assert(missing, jc.DeepEquals, set.NewStrings())
}
示例2: TestHelpCommands
func (s *MainSuite) TestHelpCommands(c *gc.C) {
defer osenv.SetJujuHome(osenv.SetJujuHome(c.MkDir()))
// Check that we have correctly registered all the commands
// by checking the help output.
// First check default commands, and then check commands that are
// activated by feature flags.
// Here we can add feature flags for any commands we want to hide by default.
devFeatures := []string{}
// remove features behind dev_flag for the first test
// since they are not enabled.
cmdSet := set.NewStrings(commandNames...)
for _, feature := range devFeatures {
cmdSet.Remove(feature)
}
// 1. Default Commands. Disable all features.
setFeatureFlags("")
c.Assert(getHelpCommandNames(c), jc.SameContents, cmdSet.Values())
// 2. Enable development features, and test again.
setFeatureFlags(strings.Join(devFeatures, ","))
c.Assert(getHelpCommandNames(c), jc.SameContents, commandNames)
}
示例3: TestBoilerPlateAliases
func (*BoilerplateConfigSuite) TestBoilerPlateAliases(c *gc.C) {
defer osenv.SetJujuHome(osenv.SetJujuHome(c.MkDir()))
boilerplate_text := environs.BoilerplateConfig()
// There should be only one occurrence of "manual", despite
// there being an alias ("null"). There should be nothing for
// aliases.
n := strings.Count(boilerplate_text, "type: manual")
c.Assert(n, gc.Equals, 1)
n = strings.Count(boilerplate_text, "type: null")
c.Assert(n, gc.Equals, 0)
}
示例4: TearDownTest
func (s *JujuOSEnvSuite) TearDownTest(c *gc.C) {
for name, value := range s.oldEnvironment {
os.Setenv(name, value)
}
utils.SetHome(s.oldHomeEnv)
osenv.SetJujuHome(s.oldJujuHome)
}
示例5: tearDownConn
func (s *JujuConnSuite) tearDownConn(c *gc.C) {
serverAlive := gitjujutesting.MgoServer.Addr() != ""
// Bootstrap will set the admin password, and render non-authorized use
// impossible. s.State may still hold the right password, so try to reset
// the password so that the MgoSuite soft-resetting works. If that fails,
// it will still work, but it will take a while since it has to kill the
// whole database and start over.
if err := s.State.SetAdminMongoPassword(""); err != nil && serverAlive {
c.Logf("cannot reset admin password: %v", err)
}
for _, st := range s.apiStates {
err := st.Close()
if serverAlive {
c.Assert(err, gc.IsNil)
}
}
err := s.Conn.Close()
if serverAlive {
c.Assert(err, gc.IsNil)
}
err = s.APIConn.Close()
if serverAlive {
c.Assert(err, gc.IsNil)
}
dummy.Reset()
s.apiStates = nil
s.Conn = nil
s.State = nil
utils.SetHome(s.oldHome)
osenv.SetJujuHome(s.oldJujuHome)
s.oldHome = ""
s.RootDir = ""
}
示例6: SetUpTest
func (s *TestingBaseSuite) SetUpTest(c *gc.C) {
utils.SetHome(home)
os.Setenv("JUJU_HOME", jujuHome)
osenv.SetJujuHome(jujuHome)
s.BaseSuite.SetUpTest(c)
}
示例7: SetUpTest
func (s *fakeHomeSuite) SetUpTest(c *gc.C) {
utils.SetHome("/home/eric")
os.Setenv("JUJU_HOME", "/home/eric/juju")
osenv.SetJujuHome("/home/eric/juju")
s.FakeJujuHomeSuite.SetUpTest(c)
}
示例8: SetUpTest
func (s *fakeHomeSuite) SetUpTest(c *gc.C) {
utils.SetHome(home)
os.Setenv("JUJU_HOME", jujuHome)
osenv.SetJujuHome(jujuHome)
s.FakeJujuHomeSuite.SetUpTest(c)
}
示例9: TestAgentNameShouldNotBeSetByHand
func (suite *EnvironProviderSuite) TestAgentNameShouldNotBeSetByHand(c *gc.C) {
testJujuHome := c.MkDir()
defer osenv.SetJujuHome(osenv.SetJujuHome(testJujuHome))
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "maas",
"maas-oauth": "aa:bb:cc",
"maas-server": "http://maas.testing.invalid/maas/",
"maas-agent-name": "foobar",
})
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
ctx := testing.Context(c)
_, err = suite.makeEnviron().Provider().Prepare(ctx, config)
c.Assert(err, gc.Equals, errAgentNameAlreadySet)
}
示例10: setUpConn
func (s *JujuConnSuite) setUpConn(c *gc.C) {
if s.RootDir != "" {
panic("JujuConnSuite.setUpConn without teardown")
}
s.RootDir = c.MkDir()
s.oldHome = utils.Home()
home := filepath.Join(s.RootDir, "/home/ubuntu")
err := os.MkdirAll(home, 0777)
c.Assert(err, gc.IsNil)
utils.SetHome(home)
s.oldJujuHome = osenv.SetJujuHome(filepath.Join(home, ".juju"))
err = os.Mkdir(osenv.JujuHome(), 0777)
c.Assert(err, gc.IsNil)
err = os.MkdirAll(s.DataDir(), 0777)
c.Assert(err, gc.IsNil)
s.PatchEnvironment(osenv.JujuEnvEnvKey, "")
// TODO(rog) remove these files and add them only when
// the tests specifically need them (in cmd/juju for example)
s.writeSampleConfig(c, osenv.JujuHomePath("environments.yaml"))
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-cert.pem"), []byte(testing.CACert), 0666)
c.Assert(err, gc.IsNil)
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-private-key.pem"), []byte(testing.CAKey), 0600)
c.Assert(err, gc.IsNil)
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
s.ConfigStore = store
ctx := testing.Context(c)
environ, err := environs.PrepareFromName("dummyenv", ctx, s.ConfigStore)
c.Assert(err, gc.IsNil)
// sanity check we've got the correct environment.
c.Assert(environ.Config().Name(), gc.Equals, "dummyenv")
s.PatchValue(&dummy.DataDir, s.DataDir())
s.LogDir = c.MkDir()
s.PatchValue(&dummy.LogDir, s.LogDir)
versions := PreferredDefaultVersions(environ.Config(), version.Binary{Number: version.Current.Number, Series: "precise", Arch: "amd64"})
versions = append(versions, version.Current)
// Upload tools for both preferred and fake default series
envtesting.MustUploadFakeToolsVersions(environ.Storage(), versions...)
err = bootstrap.Bootstrap(ctx, environ, bootstrap.BootstrapParams{})
c.Assert(err, gc.IsNil)
s.BackingState = environ.(GetStater).GetStateInAPIServer()
s.State, err = newState(environ, s.BackingState.MongoConnectionInfo())
c.Assert(err, gc.IsNil)
s.APIState, err = juju.NewAPIState(environ, api.DialOpts{})
c.Assert(err, gc.IsNil)
s.Environ = environ
}
示例11: setCacheDir
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")
}
示例12: TestHelpTopics
func (s *MainSuite) TestHelpTopics(c *gc.C) {
// Check that we have correctly registered all the topics
// by checking the help output.
defer osenv.SetJujuHome(osenv.SetJujuHome(c.MkDir()))
out := badrun(c, 0, "help", "topics")
lines := strings.Split(out, "\n")
var names []string
for _, line := range lines {
f := strings.Fields(line)
if len(f) == 0 {
continue
}
names = append(names, f[0])
}
// The names should be output in alphabetical order, so don't sort.
c.Assert(names, gc.DeepEquals, topicNames)
}
示例13: SetUpTest
func (s *BaseSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.PatchValue(&newConnection, newFakeConnection)
s.initEnv(c)
s.setUpHttpProxy(c)
s.FakeMetadataServer()
osenv.SetJujuHome(c.MkDir())
}
示例14: SetUpTest
func (s *FakeJujuHomeSuite) SetUpTest(c *gc.C) {
s.JujuOSEnvSuite.SetUpTest(c)
s.FakeHomeSuite.SetUpTest(c)
jujuHome := gitjujutesting.HomePath(".juju")
err := os.Mkdir(jujuHome, 0700)
c.Assert(err, gc.IsNil)
s.oldJujuHome = osenv.SetJujuHome(jujuHome)
WriteEnvironments(c, SingleEnvConfig, SampleCertName)
}
示例15: TestOpenReturnsNilInterfaceUponFailure
func (suite *EnvironProviderSuite) TestOpenReturnsNilInterfaceUponFailure(c *gc.C) {
testJujuHome := c.MkDir()
defer osenv.SetJujuHome(osenv.SetJujuHome(testJujuHome))
const oauth = "wrongly-formatted-oauth-string"
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "maas",
"maas-oauth": oauth,
"maas-server": "http://maas.testing.invalid/maas/",
})
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := suite.makeEnviron().Provider().Open(config)
// When Open() fails (i.e. returns a non-nil error), it returns an
// environs.Environ interface object with a nil value and a nil
// type.
c.Check(env, gc.Equals, nil)
c.Check(err, gc.ErrorMatches, ".*malformed maas-oauth.*")
}