• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang testing.HomePath函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/testing.HomePath函数的典型用法代码示例。如果您正苦于以下问题:Golang HomePath函数的具体用法?Golang HomePath怎么用?Golang HomePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了HomePath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestPrivateKeyFiles

func (s *ClientKeysSuite) TestPrivateKeyFiles(c *gc.C) {
	// Create/load client keys. They will be cached in memory:
	// any files added to the directory will not be considered
	// unless LoadClientKeys is called again.
	err := ssh.LoadClientKeys("~/.juju/ssh")
	c.Assert(err, jc.ErrorIsNil)
	checkPrivateKeyFiles(c, "~/.juju/ssh/juju_id_rsa")
	priv, pub, err := ssh.GenerateKey("whatever")
	c.Assert(err, jc.ErrorIsNil)
	err = ioutil.WriteFile(gitjujutesting.HomePath(".juju", "ssh", "whatever"), []byte(priv), 0600)
	c.Assert(err, jc.ErrorIsNil)
	err = ssh.LoadClientKeys("~/.juju/ssh")
	c.Assert(err, jc.ErrorIsNil)
	// The new private key won't be observed until the
	// corresponding public key exists.
	checkPrivateKeyFiles(c, "~/.juju/ssh/juju_id_rsa")
	err = ioutil.WriteFile(gitjujutesting.HomePath(".juju", "ssh", "whatever.pub"), []byte(pub), 0600)
	c.Assert(err, jc.ErrorIsNil)
	// new keys won't be reported until we call LoadClientKeys again
	checkPublicKeyFiles(c, "~/.juju/ssh/juju_id_rsa.pub")
	checkPrivateKeyFiles(c, "~/.juju/ssh/juju_id_rsa")
	err = ssh.LoadClientKeys("~/.juju/ssh")
	c.Assert(err, jc.ErrorIsNil)
	checkPublicKeyFiles(c, "~/.juju/ssh/juju_id_rsa.pub", "~/.juju/ssh/whatever.pub")
	checkPrivateKeyFiles(c, "~/.juju/ssh/juju_id_rsa", "~/.juju/ssh/whatever")
}
开发者ID:anastasiamac,项目名称:utils,代码行数:26,代码来源:clientkeys_test.go


示例2: TestBoilerPlatePrinted

// The boilerplate is sent to stdout with --show, and the environments.yaml
// is not created.
func (*InitSuite) TestBoilerPlatePrinted(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "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.HomePath(".juju", "environments.yaml")
	_, err = ioutil.ReadFile(environpath)
	c.Assert(err, gc.NotNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:16,代码来源:init_test.go


示例3: makeFullPlugin

func (suite *PluginSuite) makeFullPlugin(params PluginParams) {
	// Create a new template and parse the plugin into it.
	t := template.Must(template.New("plugin").Parse(pluginTemplate))
	content := &bytes.Buffer{}
	filename := gitjujutesting.HomePath("juju-" + params.Name)
	// Create the files in the temp dirs, so we don't pollute the working space
	if params.Creates != "" {
		params.Creates = gitjujutesting.HomePath(params.Creates)
	}
	if params.DependsOn != "" {
		params.DependsOn = gitjujutesting.HomePath(params.DependsOn)
	}
	t.Execute(content, params)
	ioutil.WriteFile(filename, content.Bytes(), 0755)
}
开发者ID:kat-co,项目名称:juju,代码行数:15,代码来源:plugin_test.go


示例4: TestLoadClientKeysDirExists

func (s *ClientKeysSuite) TestLoadClientKeysDirExists(c *gc.C) {
	err := os.MkdirAll(gitjujutesting.HomePath(".juju", "ssh"), 0755)
	c.Assert(err, jc.ErrorIsNil)
	err = ssh.LoadClientKeys("~/.juju/ssh")
	c.Assert(err, jc.ErrorIsNil)
	checkPrivateKeyFiles(c, "~/.juju/ssh/juju_id_rsa")
}
开发者ID:anastasiamac,项目名称:utils,代码行数:7,代码来源:clientkeys_test.go


示例5: TestBootstrapPropagatesEnvErrors

// In the case where we cannot examine an environment, we want the
// error to propagate back up to the user.
func (s *BootstrapSuite) TestBootstrapPropagatesEnvErrors(c *gc.C) {

	env := resetJujuHome(c)
	defaultSeriesVersion := version.Current
	defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
	// Force a dev version by having a non zero build number.
	// This is because we have not uploaded any tools and auto
	// upload is only enabled for dev versions.
	defaultSeriesVersion.Build = 1234
	s.PatchValue(&version.Current, defaultSeriesVersion)

	const envName = "peckham"
	_, err := coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, gc.IsNil)

	// Change permissions on the jenv file to simulate some kind of
	// unexpected error when trying to read info from the environment
	jenvFile := gitjujutesting.HomePath(".juju", "environments", envName+".jenv")
	err = os.Chmod(jenvFile, os.FileMode(0200))
	c.Assert(err, gc.IsNil)

	// The second bootstrap should fail b/c of the propogated error
	_, err = coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, gc.ErrorMatches, "there was an issue examining the environment: .*")
}
开发者ID:zhouqt,项目名称:juju,代码行数:27,代码来源:bootstrap_test.go


示例6: TestConfigPerm

func (s *suite) TestConfigPerm(c *gc.C) {
	testing.MakeSampleJujuHome(c)

	path := gitjujutesting.HomePath(".juju")
	info, err := os.Lstat(path)
	c.Assert(err, gc.IsNil)
	oldPerm := info.Mode().Perm()
	env := `
environments:
    only:
        type: dummy
        state-server: false
        authorized-keys: i-am-a-key
`
	outfile, err := environs.WriteEnvirons("", env)
	c.Assert(err, gc.IsNil)

	info, err = os.Lstat(outfile)
	c.Assert(err, gc.IsNil)
	c.Assert(info.Mode().Perm(), gc.Equals, os.FileMode(0600))

	info, err = os.Lstat(filepath.Dir(outfile))
	c.Assert(err, gc.IsNil)
	c.Assert(info.Mode().Perm(), gc.Equals, oldPerm)

}
开发者ID:rogpeppe,项目名称:juju,代码行数:26,代码来源:config_test.go


示例7: TestBoilerPlateEnvironment

// The environments.yaml is created by default if it
// does not already exist.
func (*InitSuite) TestBoilerPlateEnvironment(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "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 environment configuration file has been written.*")
	environpath := gitjujutesting.HomePath(".juju", "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.*")
}
开发者ID:imoapps,项目名称:juju,代码行数:18,代码来源:init_test.go


示例8: TestNoEnvironment

func (*SwitchSimpleSuite) TestNoEnvironment(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "environments.yaml")
	err := os.Remove(envPath)
	c.Assert(err, jc.ErrorIsNil)
	_, err = testing.RunCommand(c, &SwitchCommand{})
	c.Assert(err, gc.ErrorMatches, "couldn't read the environment")
}
开发者ID:Pankov404,项目名称:juju,代码行数:7,代码来源:switch_test.go


示例9: TestConfigPerm

func (s *suite) TestConfigPerm(c *gc.C) {
	testing.MakeSampleJujuHome(c)

	path := gitjujutesting.HomePath(".juju")
	info, err := os.Lstat(path)
	c.Assert(err, jc.ErrorIsNil)
	oldPerm := info.Mode().Perm()
	env := `
environments:
    only:
        type: dummy
        state-server: 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)
	}

}
开发者ID:imoapps,项目名称:juju,代码行数:32,代码来源:config_test.go


示例10: TestBootstrapPropagatesEnvErrors

// In the case where we cannot examine an environment, we want the
// error to propagate back up to the user.
func (s *BootstrapSuite) TestBootstrapPropagatesEnvErrors(c *gc.C) {
	//TODO(bogdanteleaga): fix this for windows once permissions are fixed
	if runtime.GOOS == "windows" {
		c.Skip("bug 1403084: this is very platform specific. When/if we will support windows state machine, this will probably be rewritten.")
	}

	const envName = "devenv"
	env := resetJujuHome(c, envName)
	defaultSeriesVersion := version.Current
	defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
	// Force a dev version by having a non zero build number.
	// This is because we have not uploaded any tools and auto
	// upload is only enabled for dev versions.
	defaultSeriesVersion.Build = 1234
	s.PatchValue(&version.Current, defaultSeriesVersion)
	s.PatchValue(&environType, func(string) (string, error) { return "", nil })

	_, err := coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, jc.ErrorIsNil)

	// Change permissions on the jenv file to simulate some kind of
	// unexpected error when trying to read info from the environment
	jenvFile := gitjujutesting.HomePath(".juju", "environments", envName+".jenv")
	err = os.Chmod(jenvFile, os.FileMode(0200))
	c.Assert(err, jc.ErrorIsNil)

	// The second bootstrap should fail b/c of the propogated error
	_, err = coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, gc.ErrorMatches, "there was an issue examining the environment: .*")
}
开发者ID:kakamessi99,项目名称:juju,代码行数:32,代码来源:bootstrap_test.go


示例11: TestNoDefaultNoEnvironmentsFile

func (*SwitchSimpleSuite) TestNoDefaultNoEnvironmentsFile(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "environments.yaml")
	err := os.Remove(envPath)
	c.Assert(err, jc.ErrorIsNil)
	_, err = testing.RunCommand(c, newSwitchCommand())
	c.Assert(err, gc.ErrorMatches, "no currently specified environment")
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:switch_test.go


示例12: TestGetDefaultModelNothingSet

func (s *ModelCommandSuite) TestGetDefaultModelNothingSet(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "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)
}
开发者ID:pmatulis,项目名称:juju,代码行数:8,代码来源:modelcommand_test.go


示例13: TestSystemCommandInitNoEnvFile

func (s *SystemCommandSuite) TestSystemCommandInitNoEnvFile(c *gc.C) {
	// Since we ignore the environments.yaml file, we don't care if it isn't
	// there.
	envPath := gitjujutesting.HomePath(".juju", "environments.yaml")
	err := os.Remove(envPath)
	_, err = initTestSystemCommand(c)
	c.Assert(err, gc.ErrorMatches, "no system specified")
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:8,代码来源:systemcommand_test.go


示例14: TestGetDefaultEnvironmentNothingSet

func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentNothingSet(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "environments.yaml")
	err := os.Remove(envPath)
	c.Assert(err, gc.IsNil)
	env, err := envcmd.GetDefaultEnvironment()
	c.Assert(env, gc.Equals, "")
	c.Assert(err, jc.Satisfies, environs.IsNoEnv)
}
开发者ID:klyachin,项目名称:juju,代码行数:8,代码来源:environmentcommand_test.go


示例15: TestNoEnv

func (*suite) TestNoEnv(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "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)
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:config_test.go


示例16: TestNoEnvironmentReadsConfigStore

func (s *SwitchSimpleSuite) TestNoEnvironmentReadsConfigStore(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "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")
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:switch_test.go


示例17: SetUpTest

func (suite *PluginSuite) SetUpTest(c *gc.C) {
	//TODO(bogdanteleaga): Fix bash tests
	if runtime.GOOS == "windows" {
		c.Skip("bug 1403084: tests use bash scrips, will be rewritten for windows")
	}
	suite.FakeJujuXDGDataHomeSuite.SetUpTest(c)
	suite.oldPath = os.Getenv("PATH")
	os.Setenv("PATH", "/bin:"+gitjujutesting.HomePath())
}
开发者ID:kat-co,项目名称:juju,代码行数:9,代码来源:plugin_test.go


示例18: 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)
}
开发者ID:kapilt,项目名称:juju,代码行数:9,代码来源:environ.go


示例19: TestSshDirSetUp

func (s *fakeHomeSuite) TestSshDirSetUp(c *gc.C) {
	// The SSH directory is properly created and set up.
	s.fakeHomeSuite.SetUpTest(c)
	sshDir := testing.HomePath(".ssh")
	c.Assert(sshDir, jc.IsDirectory)
	PrivKeyFile := filepath.Join(sshDir, "id_rsa")
	c.Assert(PrivKeyFile, jc.IsNonEmptyFile)
	PubKeyFile := filepath.Join(sshDir, "id_rsa.pub")
	c.Assert(PubKeyFile, jc.IsNonEmptyFile)
	s.fakeHomeSuite.TearDownTest(c)
}
开发者ID:fabricematrat,项目名称:testing,代码行数:11,代码来源:home_test.go


示例20: resetJujuHome

// resetJujuHome restores an new, clean Juju home environment without tools.
func resetJujuHome(c *gc.C, envName string) environs.Environ {
	jenvDir := gitjujutesting.HomePath(".juju", "environments")
	err := os.RemoveAll(jenvDir)
	c.Assert(err, jc.ErrorIsNil)
	coretesting.WriteEnvironments(c, envConfig)
	dummy.Reset()
	store, err := configstore.Default()
	c.Assert(err, jc.ErrorIsNil)
	env, err := environs.PrepareFromName(envName, envcmd.BootstrapContext(cmdtesting.NullContext(c)), store)
	c.Assert(err, jc.ErrorIsNil)
	return env
}
开发者ID:kakamessi99,项目名称:juju,代码行数:13,代码来源:bootstrap_test.go



注:本文中的github.com/juju/testing.HomePath函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang testing.JujuXDGDataHomePath函数代码示例发布时间:2022-05-23
下一篇:
Golang testing.AssertEchoArgs函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap