本文整理汇总了Golang中github.com/juju/juju/testing.MakeSampleJujuHome函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeSampleJujuHome函数的具体用法?Golang MakeSampleJujuHome怎么用?Golang MakeSampleJujuHome使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeSampleJujuHome函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: TestMultipleCloseOk
// TODO(jam): 2013-08-27 This should move somewhere in api.*
func (s *NewAPIClientSuite) TestMultipleCloseOk(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
bootstrapEnv(c, "", defaultConfigStore(c))
client, _ := juju.NewAPIClientFromName("")
c.Assert(client.Close(), gc.IsNil)
c.Assert(client.Close(), gc.IsNil)
c.Assert(client.Close(), gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:9,代码来源:api_test.go
示例4: TestNewConnFromNameNotSetGetsDefault
func (s *NewConnSuite) TestNewConnFromNameNotSetGetsDefault(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
bootstrapEnv(c, "", defaultConfigStore(c))
conn, err := juju.NewConnFromName("")
c.Assert(err, gc.IsNil)
defer assertClose(c, conn)
c.Assert(conn.Environ.Name(), gc.Equals, coretesting.SampleEnvName)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:8,代码来源:conn_test.go
示例5: TestWithConfigAndNoInfo
func (s *NewAPIClientSuite) TestWithConfigAndNoInfo(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
store := newConfigStore(coretesting.SampleEnvName, &environInfo{
bootstrapConfig: map[string]interface{}{
"type": "dummy",
"name": "myenv",
"state-server": true,
"authorized-keys": "i-am-a-key",
"default-series": config.LatestLtsSeries(),
"firewall-mode": config.FwInstance,
"development": false,
"ssl-hostname-verification": true,
"admin-secret": "adminpass",
},
})
bootstrapEnv(c, coretesting.SampleEnvName, store)
// Verify the cache is empty.
info, err := store.ReadInfo("myenv")
c.Assert(err, gc.IsNil)
c.Assert(info, gc.NotNil)
c.Assert(info.APIEndpoint(), jc.DeepEquals, configstore.APIEndpoint{})
c.Assert(info.APICredentials(), jc.DeepEquals, configstore.APICredentials{})
called := 0
expectState := mockedAPIState(0)
apiOpen := func(apiInfo *api.Info, opts api.DialOpts) (juju.APIState, error) {
c.Check(apiInfo.Tag, gc.Equals, names.NewUserTag("admin"))
c.Check(string(apiInfo.CACert), gc.Not(gc.Equals), "")
c.Check(apiInfo.Password, gc.Equals, "adminpass")
// EnvironTag wasn't in regular Config
c.Check(apiInfo.EnvironTag, gc.IsNil)
c.Check(opts, gc.DeepEquals, api.DefaultDialOpts())
called++
return expectState, nil
}
st, err := juju.NewAPIFromStore("myenv", store, apiOpen)
c.Assert(err, gc.IsNil)
c.Assert(st, gc.Equals, expectState)
c.Assert(called, gc.Equals, 1)
// Make sure the cache is updated.
info, err = store.ReadInfo("myenv")
c.Assert(err, gc.IsNil)
c.Assert(info, gc.NotNil)
ep := info.APIEndpoint()
c.Assert(ep.Addresses, gc.HasLen, 1)
c.Check(ep.Addresses[0], gc.Matches, `localhost:\d+`)
c.Check(ep.CACert, gc.Not(gc.Equals), "")
// Old servers won't hand back EnvironTag, so it should stay empty in
// the cache
c.Check(ep.EnvironUUID, gc.Equals, "")
creds := info.APICredentials()
c.Check(creds.User, gc.Equals, "admin")
c.Check(creds.Password, gc.Equals, "adminpass")
}
开发者ID:klyachin,项目名称:juju,代码行数:57,代码来源:api_test.go
示例6: TestConnMultipleCloseOk
func (s *NewConnSuite) TestConnMultipleCloseOk(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
bootstrapEnv(c, "", defaultConfigStore(c))
// Error return from here is tested in TestNewConnFromNameNotSetGetsDefault.
conn, err := juju.NewConnFromName("")
c.Assert(err, gc.IsNil)
assertClose(c, conn)
assertClose(c, conn)
assertClose(c, conn)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:10,代码来源:conn_test.go
示例7: TestImageMetadataBadArgs
func (s *ImageMetadataSuite) TestImageMetadataBadArgs(c *gc.C) {
testing.MakeSampleJujuHome(c)
s.AddCleanup(func(*gc.C) {
dummy.Reset()
})
for i, t := range errTests {
c.Logf("test: %d", i)
ctx := testing.Context(c)
code := cmd.Main(envcmd.Wrap(&ImageMetadataCommand{}), ctx, t.args)
c.Check(code, gc.Equals, 1)
}
}
开发者ID:Pankov404,项目名称:juju,代码行数:12,代码来源:imagemetadata_test.go
示例8: TestWithSlowInfoConnect
func (s *NewAPIClientSuite) TestWithSlowInfoConnect(c *gc.C) {
s.PatchValue(&version.Current, coretesting.FakeVersionNumber)
coretesting.MakeSampleJujuHome(c)
store := configstore.NewMem()
s.bootstrapEnv(c, coretesting.SampleModelName, store)
setEndpointAddressAndHostname(c, store, coretesting.SampleModelName, "0.1.2.3", "infoapi.invalid")
infoOpenedState := mockedAPIState(noFlags)
infoEndpointOpened := make(chan struct{})
cfgOpenedState := mockedAPIState(noFlags)
// On a sample run with no delay, the logic took 45ms to run, so
// we make the delay slightly more than that, so that if the
// logic doesn't delay at all, the test will fail reasonably consistently.
s.PatchValue(juju.ProviderConnectDelay, 50*time.Millisecond)
apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
if info.Addrs[0] == "0.1.2.3" {
infoEndpointOpened <- struct{}{}
return infoOpenedState, nil
}
return cfgOpenedState, nil
}
stateClosed := make(chan api.Connection)
infoOpenedState.close = func(st api.Connection) error {
stateClosed <- st
return nil
}
cfgOpenedState.close = infoOpenedState.close
startTime := time.Now()
st, err := juju.NewAPIFromStore(coretesting.SampleModelName, store, apiOpen)
c.Assert(err, jc.ErrorIsNil)
// The connection logic should wait for some time before opening
// the API from the configuration.
c.Assert(time.Since(startTime), jc.GreaterThan, *juju.ProviderConnectDelay)
c.Assert(st, gc.Equals, cfgOpenedState)
select {
case <-infoEndpointOpened:
case <-time.After(coretesting.LongWait):
c.Errorf("api never opened via info")
}
// Check that the ignored state was closed.
select {
case st := <-stateClosed:
c.Assert(st, gc.Equals, infoOpenedState)
case <-time.After(coretesting.LongWait):
c.Errorf("timed out waiting for state to be closed")
}
}
开发者ID:pmatulis,项目名称:juju,代码行数:51,代码来源:api_test.go
示例9: TestWithConfigAndNoInfo
func (s *NewAPIClientSuite) TestWithConfigAndNoInfo(c *gc.C) {
c.Skip("not really possible now that there is no defined admin user")
s.PatchValue(&version.Current, coretesting.FakeVersionNumber)
coretesting.MakeSampleJujuHome(c)
store := newConfigStore(coretesting.SampleModelName, &environInfo{
bootstrapConfig: map[string]interface{}{
"type": "dummy",
"name": "myenv",
"state-server": true,
"authorized-keys": "i-am-a-key",
"default-series": config.LatestLtsSeries(),
"firewall-mode": config.FwInstance,
"development": false,
"ssl-hostname-verification": true,
"admin-secret": "adminpass",
},
})
s.bootstrapEnv(c, coretesting.SampleModelName, store)
info, err := store.ReadInfo("myenv")
c.Assert(err, jc.ErrorIsNil)
c.Assert(info, gc.NotNil)
c.Logf("%#v", info.APICredentials())
called := 0
expectState := mockedAPIState(0)
apiOpen := func(apiInfo *api.Info, opts api.DialOpts) (api.Connection, error) {
c.Check(apiInfo.Tag, gc.Equals, dummy.AdminUserTag())
c.Check(string(apiInfo.CACert), gc.Not(gc.Equals), "")
c.Check(apiInfo.Password, gc.Equals, "adminpass")
// ModelTag wasn't in regular Config
c.Check(apiInfo.ModelTag.Id(), gc.Equals, "")
c.Check(opts, gc.DeepEquals, api.DefaultDialOpts())
called++
return expectState, nil
}
st, err := juju.NewAPIFromStore("myenv", store, apiOpen)
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.Equals, expectState)
c.Assert(called, gc.Equals, 1)
// Make sure the cache is updated.
info, err = store.ReadInfo("myenv")
c.Assert(err, jc.ErrorIsNil)
c.Assert(info, gc.NotNil)
ep := info.APIEndpoint()
c.Assert(ep.Addresses, gc.HasLen, 1)
c.Check(ep.Addresses[0], gc.Matches, `localhost:\d+`)
c.Check(ep.CACert, gc.Not(gc.Equals), "")
}
开发者ID:pmatulis,项目名称:juju,代码行数:51,代码来源:api_test.go
示例10: TestBothError
func (s *NewAPIClientSuite) TestBothError(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
store := configstore.NewMem()
s.bootstrapEnv(c, coretesting.SampleEnvName, store)
setEndpointAddressAndHostname(c, store, coretesting.SampleEnvName, "0.1.2.3", "infoapi.invalid")
s.PatchValue(juju.ProviderConnectDelay, 0*time.Second)
apiOpen := func(info *api.Info, opts api.DialOpts) (juju.APIState, error) {
if info.Addrs[0] == "infoapi.invalid" {
return nil, fmt.Errorf("info connect failed")
}
return nil, fmt.Errorf("config connect failed")
}
st, err := juju.NewAPIFromStore(coretesting.SampleEnvName, store, apiOpen)
c.Check(err, gc.ErrorMatches, "config connect failed")
c.Check(st, gc.IsNil)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:17,代码来源:api_test.go
示例11: TestWithBootstrapConfigAndNoEnvironmentsFile
func (s *NewAPIClientSuite) TestWithBootstrapConfigAndNoEnvironmentsFile(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
store := configstore.NewMem()
s.bootstrapEnv(c, coretesting.SampleEnvName, store)
info, err := store.ReadInfo(coretesting.SampleEnvName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(info.BootstrapConfig(), gc.NotNil)
c.Assert(info.APIEndpoint().Addresses, gc.HasLen, 0)
err = os.Remove(osenv.JujuHomePath("environments.yaml"))
c.Assert(err, jc.ErrorIsNil)
apiOpen := func(*api.Info, api.DialOpts) (juju.APIState, error) {
return mockedAPIState(noFlags), nil
}
st, err := juju.NewAPIFromStore(coretesting.SampleEnvName, store, apiOpen)
c.Check(err, jc.ErrorIsNil)
st.Close()
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:19,代码来源:api_test.go
示例12: TestWithSlowConfigConnect
func (s *NewAPIClientSuite) TestWithSlowConfigConnect(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
store := configstore.NewMem()
s.bootstrapEnv(c, coretesting.SampleEnvName, store)
setEndpointAddressAndHostname(c, store, coretesting.SampleEnvName, "0.1.2.3", "infoapi.invalid")
infoOpenedState := mockedAPIState(noFlags)
infoEndpointOpened := make(chan struct{})
cfgOpenedState := mockedAPIState(noFlags)
cfgEndpointOpened := make(chan struct{})
s.PatchValue(juju.ProviderConnectDelay, 0*time.Second)
apiOpen := func(info *api.Info, opts api.DialOpts) (juju.APIState, error) {
if info.Addrs[0] == "0.1.2.3" {
infoEndpointOpened <- struct{}{}
<-infoEndpointOpened
return infoOpenedState, nil
}
cfgEndpointOpened <- struct{}{}
<-cfgEndpointOpened
return cfgOpenedState, nil
}
stateClosed := make(chan juju.APIState)
infoOpenedState.close = func(st juju.APIState) error {
stateClosed <- st
return nil
}
cfgOpenedState.close = infoOpenedState.close
done := make(chan struct{})
go func() {
st, err := juju.NewAPIFromStore(coretesting.SampleEnvName, store, apiOpen)
c.Check(err, jc.ErrorIsNil)
c.Check(st, gc.Equals, infoOpenedState)
close(done)
}()
// Check that we're trying to connect to both endpoints:
select {
case <-infoEndpointOpened:
case <-time.After(coretesting.LongWait):
c.Fatalf("api never opened via info")
}
select {
case <-cfgEndpointOpened:
case <-time.After(coretesting.LongWait):
c.Fatalf("api never opened via config")
}
// Let the info endpoint open go ahead and
// check that the NewAPIFromStore call returns.
infoEndpointOpened <- struct{}{}
select {
case <-done:
case <-time.After(coretesting.LongWait):
c.Errorf("timed out opening API")
}
// Let the config endpoint open go ahead and
// check that its state is closed.
cfgEndpointOpened <- struct{}{}
select {
case st := <-stateClosed:
c.Assert(st, gc.Equals, cfgOpenedState)
case <-time.After(coretesting.LongWait):
c.Errorf("timed out waiting for state to be closed")
}
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:69,代码来源:api_test.go
注:本文中的github.com/juju/juju/testing.MakeSampleJujuHome函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论