本文整理汇总了Golang中github.com/juju/testing.JujuXDGDataHomePath函数的典型用法代码示例。如果您正苦于以下问题:Golang JujuXDGDataHomePath函数的具体用法?Golang JujuXDGDataHomePath怎么用?Golang JujuXDGDataHomePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JujuXDGDataHomePath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBoilerPlatePrinted
// The boilerplate is sent to stdout with --show, and the environments.yaml
// is not created.
func (*InitSuite) TestBoilerPlatePrinted(c *gc.C) {
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Remove(envPath)
c.Assert(err, jc.ErrorIsNil)
ctx := testing.Context(c)
code := cmd.Main(&initCommand{}, ctx, []string{"--show"})
c.Check(code, gc.Equals, 0)
outStr := ctx.Stdout.(*bytes.Buffer).String()
strippedOut := strings.Replace(outStr, "\n", "", -1)
c.Check(strippedOut, gc.Matches, ".*# This is the Juju config file, which you can use.*")
environpath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
_, err = ioutil.ReadFile(environpath)
c.Assert(err, gc.NotNil)
}
示例2: TestConfigPerm
func (s *suite) TestConfigPerm(c *gc.C) {
testing.MakeSampleJujuHome(c)
path := gitjujutesting.JujuXDGDataHomePath()
info, err := os.Lstat(path)
c.Assert(err, jc.ErrorIsNil)
oldPerm := info.Mode().Perm()
env := `
environments:
only:
type: dummy
controller: false
authorized-keys: i-am-a-key
`
outfile, err := environs.WriteEnvirons("", env)
c.Assert(err, jc.ErrorIsNil)
info, err = os.Lstat(outfile)
c.Assert(err, jc.ErrorIsNil)
// Windows is not fully POSIX compliant. Normal permission
// checking will yield unexpected results
if runtime.GOOS != "windows" {
c.Assert(info.Mode().Perm(), gc.Equals, os.FileMode(0600))
}
info, err = os.Lstat(filepath.Dir(outfile))
c.Assert(err, jc.ErrorIsNil)
if runtime.GOOS != "windows" {
c.Assert(info.Mode().Perm(), gc.Equals, oldPerm)
}
}
示例3: TestNoDefaultNoEnvironmentsFile
func (*SwitchSimpleSuite) TestNoDefaultNoEnvironmentsFile(c *gc.C) {
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Remove(envPath)
c.Assert(err, jc.ErrorIsNil)
_, err = testing.RunCommand(c, newSwitchCommand())
c.Assert(err, gc.ErrorMatches, "no currently specified model")
}
示例4: TestBoilerPlateEnvironment
// The environments.yaml is created by default if it
// does not already exist.
func (*InitSuite) TestBoilerPlateEnvironment(c *gc.C) {
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Remove(envPath)
c.Assert(err, jc.ErrorIsNil)
ctx := testing.Context(c)
code := cmd.Main(&initCommand{}, ctx, nil)
c.Check(code, gc.Equals, 0)
outStr := ctx.Stdout.(*bytes.Buffer).String()
strippedOut := strings.Replace(outStr, "\n", "", -1)
c.Check(strippedOut, gc.Matches, ".*A boilerplate model configuration file has been written.*")
environpath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
data, err := ioutil.ReadFile(environpath)
c.Assert(err, jc.ErrorIsNil)
strippedData := strings.Replace(string(data), "\n", "", -1)
c.Assert(strippedData, gc.Matches, ".*# This is the Juju config file, which you can use.*")
}
示例5: SetUpTest
func (s *jenvSuite) SetUpTest(c *gc.C) {
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
dir := gitjujutesting.JujuXDGDataHomePath()
err := os.MkdirAll(dir, 0600)
c.Check(err, jc.ErrorIsNil)
}
示例6: SetUpTest
func (s *FakeJujuXDGDataHomeSuite) SetUpTest(c *gc.C) {
s.JujuOSEnvSuite.SetUpTest(c)
s.FakeHomeSuite.SetUpTest(c)
jujuXDGDataHome := gitjujutesting.JujuXDGDataHomePath()
err := os.MkdirAll(jujuXDGDataHome, 0700)
c.Assert(err, jc.ErrorIsNil)
s.oldJujuXDGDataHome = osenv.SetJujuXDGDataHome(jujuXDGDataHome)
}
示例7: TestGetDefaultModelNothingSet
func (s *ModelCommandSuite) TestGetDefaultModelNothingSet(c *gc.C) {
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Remove(envPath)
c.Assert(err, jc.ErrorIsNil)
env, err := modelcmd.GetDefaultModel()
c.Assert(env, gc.Equals, "")
c.Assert(err, jc.ErrorIsNil)
}
示例8: TestNoEnv
func (*suite) TestNoEnv(c *gc.C) {
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Remove(envPath)
c.Assert(err, jc.ErrorIsNil)
es, err := environs.ReadEnvirons("")
c.Assert(es, gc.IsNil)
c.Assert(err, jc.Satisfies, environs.IsNoEnv)
}
示例9: TestControllerCommandInitNoEnvFile
func (s *ControllerCommandSuite) TestControllerCommandInitNoEnvFile(c *gc.C) {
// Since we ignore the environments.yaml file, we don't care if it isn't
// there.
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Remove(envPath)
_, err = initTestControllerCommand(c)
c.Assert(err, gc.ErrorMatches, "no controller specified")
}
示例10: SetUpTest
func (s *FakeJujuXDGDataHomeSuite) SetUpTest(c *gc.C) {
s.JujuOSEnvSuite.SetUpTest(c)
s.FakeHomeSuite.SetUpTest(c)
jujuXDGDataHome := gitjujutesting.JujuXDGDataHomePath()
err := os.MkdirAll(jujuXDGDataHome, 0700)
c.Assert(err, jc.ErrorIsNil)
s.oldJujuXDGDataHome = osenv.SetJujuXDGDataHome(jujuXDGDataHome)
WriteEnvironments(c, SingleEnvConfig, SampleCertName)
}
示例11: TestNoEnvironmentReadsConfigStore
func (s *SwitchSimpleSuite) TestNoEnvironmentReadsConfigStore(c *gc.C) {
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Remove(envPath)
c.Assert(err, jc.ErrorIsNil)
s.addTestController(c)
context, err := testing.RunCommand(c, newSwitchCommand(), "--list")
c.Assert(err, jc.ErrorIsNil)
c.Assert(testing.Stdout(context), gc.Equals, "a-controller (controller)\n")
}
示例12: TestErrorReadingEnvironmentsFile
func (s *SwitchSimpleSuite) TestErrorReadingEnvironmentsFile(c *gc.C) {
if runtime.GOOS == "windows" {
c.Skip("bug 1496997: os.Chmod doesn't exist on windows, checking this on one platform is sufficent to test this case")
}
envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
err := os.Chmod(envPath, 0)
c.Assert(err, jc.ErrorIsNil)
s.addTestController(c)
_, err = testing.RunCommand(c, newSwitchCommand(), "--list")
c.Assert(err, gc.ErrorMatches, "couldn't read the model: open .*: permission denied")
}
示例13: resetJujuXDGDataHome
// resetJujuXDGDataHome restores an new, clean Juju home environment without tools.
func resetJujuXDGDataHome(c *gc.C, envName string) environs.Environ {
jenvDir := testing.JujuXDGDataHomePath("models")
err := os.RemoveAll(jenvDir)
c.Assert(err, jc.ErrorIsNil)
coretesting.WriteEnvironments(c, modelConfig)
dummy.Reset()
store, err := configstore.Default()
c.Assert(err, jc.ErrorIsNil)
env, err := environs.PrepareFromName(envName, modelcmd.BootstrapContext(cmdtesting.NullContext(c)), store)
c.Assert(err, jc.ErrorIsNil)
return env
}
示例14: TestExistingEnvironmentNotOverwritten
// An existing environments.yaml will not be overwritten without
// the explicit -f option.
func (*InitSuite) TestExistingEnvironmentNotOverwritten(c *gc.C) {
testing.WriteEnvironments(c, existingEnv)
ctx := testing.Context(c)
code := cmd.Main(&initCommand{}, ctx, nil)
c.Check(code, gc.Equals, 1)
errOut := ctx.Stderr.(*bytes.Buffer).String()
strippedOut := strings.Replace(errOut, "\n", "", -1)
c.Check(strippedOut, gc.Matches, ".*A juju model configuration already exists.*")
environpath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
data, err := ioutil.ReadFile(environpath)
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(data), gc.Equals, existingEnv)
}
示例15: assertJenvContents
// assertJenvContents checks that the jenv file corresponding to the given
// envName is correctly present in the Juju Home and has the given contents.
func assertJenvContents(c *gc.C, contents []byte, envName string) {
path := gitjujutesting.JujuXDGDataHomePath("models", envName+".jenv")
// Ensure the jenv file has been created.
c.Assert(path, jc.IsNonEmptyFile)
// Retrieve the jenv file contents.
b, err := ioutil.ReadFile(path)
c.Assert(err, jc.ErrorIsNil)
// Ensure the jenv file reflects the source contents.
var data map[string]interface{}
err = yaml.Unmarshal(contents, &data)
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(b), jc.YAMLEquals, data)
}