本文整理汇总了Golang中github.com/juju/juju/cmd/envcmd.WriteCurrentSystem函数的典型用法代码示例。如果您正苦于以下问题:Golang WriteCurrentSystem函数的具体用法?Golang WriteCurrentSystem怎么用?Golang WriteCurrentSystem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WriteCurrentSystem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *EnvironmentsSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
err := envcmd.WriteCurrentSystem("fake")
c.Assert(err, jc.ErrorIsNil)
last1 := time.Date(2015, 3, 20, 0, 0, 0, 0, time.UTC)
last2 := time.Date(2015, 3, 1, 0, 0, 0, 0, time.UTC)
envs := []base.UserEnvironment{
{
Name: "test-env1",
Owner: "[email protected]",
UUID: "test-env1-UUID",
LastConnection: &last1,
}, {
Name: "test-env2",
Owner: "[email protected]",
UUID: "test-env2-UUID",
LastConnection: &last2,
}, {
Name: "test-env3",
Owner: "[email protected]",
UUID: "test-env3-UUID",
},
}
s.api = &fakeEnvMgrAPIClient{envs: envs}
s.creds = &configstore.APICredentials{User: "[email protected]", Password: "password"}
}
示例2: TestWriteSystemRemovesEnvironmentFile
func (s *filesSuite) TestWriteSystemRemovesEnvironmentFile(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, jc.ErrorIsNil)
err = envcmd.WriteCurrentSystem("baz")
c.Assert(err, jc.ErrorIsNil)
c.Assert(envcmd.GetCurrentEnvironmentFilePath(), jc.DoesNotExist)
}
示例3: TestWriteSystemAddsNewline
func (s *filesSuite) TestWriteSystemAddsNewline(c *gc.C) {
err := envcmd.WriteCurrentSystem("fubar")
c.Assert(err, jc.ErrorIsNil)
current, err := ioutil.ReadFile(envcmd.GetCurrentSystemFilePath())
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(current), gc.Equals, "fubar\n")
}
示例4: TestEnvironCommandInitSystemFile
func (s *EnvironmentCommandSuite) TestEnvironCommandInitSystemFile(c *gc.C) {
// If there is a current-system file, error raised.
err := envcmd.WriteCurrentSystem("fubar")
c.Assert(err, jc.ErrorIsNil)
_, err = initTestCommand(c)
c.Assert(err, gc.ErrorMatches, `not operating on an environment, using system "fubar"`)
}
示例5: TestCurrentSystemHasPrecedence
func (s *SwitchSimpleSuite) TestCurrentSystemHasPrecedence(c *gc.C) {
testing.WriteEnvironments(c, testing.MultipleEnvConfig)
envcmd.WriteCurrentSystem("fubar")
context, err := testing.RunCommand(c, &SwitchCommand{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(testing.Stdout(context), gc.Equals, "fubar (system)\n")
}
示例6: SetUpTest
func (s *BaseSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
memstore := configstore.NewMem()
s.PatchValue(&configstore.Default, func() (configstore.Storage, error) {
return memstore, nil
})
os.Setenv(osenv.JujuEnvEnvKey, "testing")
info := memstore.CreateInfo("testing")
info.SetBootstrapConfig(map[string]interface{}{"random": "extra data"})
info.SetAPIEndpoint(configstore.APIEndpoint{
Addresses: []string{"127.0.0.1:12345"},
Hostnames: []string{"localhost:12345"},
CACert: testing.CACert,
EnvironUUID: "env-uuid",
})
info.SetAPICredentials(configstore.APICredentials{
User: "user-test",
Password: "password",
})
err := info.Write()
c.Assert(err, jc.ErrorIsNil)
s.PatchValue(user.ReadPassword, func() (string, error) {
return "sekrit", nil
})
err = envcmd.WriteCurrentSystem("testing")
c.Assert(err, jc.ErrorIsNil)
}
示例7: SetUpTest
func (s *removeBlocksSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
err := envcmd.WriteCurrentSystem("fake")
c.Assert(err, jc.ErrorIsNil)
s.api = &fakeRemoveBlocksAPI{}
}
示例8: TestCurrentCommenctionNameSystem
func (*filesSuite) TestCurrentCommenctionNameSystem(c *gc.C) {
err := envcmd.WriteCurrentSystem("baz")
c.Assert(err, jc.ErrorIsNil)
name, isSystem, err := envcmd.CurrentConnectionName()
c.Assert(err, jc.ErrorIsNil)
c.Assert(isSystem, jc.IsTrue)
c.Assert(name, gc.Equals, "baz")
}
示例9: TestSystemCommandInitExplicit
func (s *SystemCommandSuite) TestSystemCommandInitExplicit(c *gc.C) {
// Take system name from command line arg, and it trumps the current-
// system file.
err := envcmd.WriteCurrentSystem("fubar")
c.Assert(err, jc.ErrorIsNil)
testEnsureSystemName(c, "explicit", "-s", "explicit")
testEnsureSystemName(c, "explicit", "--system", "explicit")
}
示例10: TestSetCurrentSystemExistingSystem
func (s *filesSuite) TestSetCurrentSystemExistingSystem(c *gc.C) {
err := envcmd.WriteCurrentSystem("fubar")
c.Assert(err, jc.ErrorIsNil)
ctx := testing.Context(c)
err = envcmd.SetCurrentSystem(ctx, "new-sys")
c.Assert(err, jc.ErrorIsNil)
s.assertCurrentSystem(c, "new-sys")
c.Assert(testing.Stderr(ctx), gc.Equals, "fubar (system) -> new-sys (system)\n")
}
示例11: TestSystemEnvironmentsCommand
func (s *cmdSystemSuite) TestSystemEnvironmentsCommand(c *gc.C) {
c.Assert(envcmd.WriteCurrentSystem("dummyenv"), jc.ErrorIsNil)
s.createEnv(c, "new-env", false)
context := s.run(c, "environments")
c.Assert(testing.Stdout(context), gc.Equals, ""+
"NAME OWNER LAST CONNECTION\n"+
"dummyenv [email protected] just now\n"+
"new-env [email protected] never connected\n"+
"\n")
}
示例12: TestRemoveBlocks
func (s *cmdSystemSuite) TestRemoveBlocks(c *gc.C) {
c.Assert(envcmd.WriteCurrentSystem("dummyenv"), jc.ErrorIsNil)
s.State.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
s.State.SwitchBlockOn(state.ChangeBlock, "TestChangeBlock")
s.run(c, "remove-blocks")
blocks, err := s.State.AllBlocksForSystem()
c.Assert(err, jc.ErrorIsNil)
c.Assert(blocks, gc.HasLen, 0)
}
示例13: TestListBlocks
func (s *cmdSystemSuite) TestListBlocks(c *gc.C) {
c.Assert(envcmd.WriteCurrentSystem("dummyenv"), jc.ErrorIsNil)
s.State.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
s.State.SwitchBlockOn(state.ChangeBlock, "TestChangeBlock")
ctx := s.run(c, "list-blocks", "--format", "json")
expected := fmt.Sprintf(`[{"name":"dummyenv","env-uuid":"%s","owner-tag":"%s","blocks":["BlockDestroy","BlockChange"]}]`,
s.State.EnvironUUID(), s.AdminUserTag(c).String())
strippedOut := strings.Replace(testing.Stdout(ctx), "\n", "", -1)
c.Check(strippedOut, gc.Equals, expected)
}
示例14: TestCreateEnvironment
func (s *cmdSystemSuite) TestCreateEnvironment(c *gc.C) {
c.Assert(envcmd.WriteCurrentSystem("dummyenv"), jc.ErrorIsNil)
// The JujuConnSuite doesn't set up an ssh key in the fake home dir,
// so fake one on the command line. The dummy provider also expects
// a config value for 'state-server'.
context := s.run(c, "create-environment", "new-env", "authorized-keys=fake-key", "state-server=false")
c.Check(testing.Stdout(context), gc.Equals, "")
c.Check(testing.Stderr(context), gc.Equals, `
created environment "new-env"
dummyenv (system) -> new-env
`[1:])
// Make sure that the saved server details are sufficient to connect
// to the api server.
api, err := juju.NewAPIFromName("new-env")
c.Assert(err, jc.ErrorIsNil)
api.Close()
}
示例15: SetUpTest
func (s *UseEnvironmentSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
err := envcmd.WriteCurrentSystem("fake")
c.Assert(err, jc.ErrorIsNil)
envs := []base.UserEnvironment{{
Name: "unique",
Owner: "[email protected]",
UUID: "some-uuid",
}, {
Name: "test",
Owner: "[email protected]",
UUID: env1UUID,
}, {
Name: "test",
Owner: "[email protected]",
UUID: env2UUID,
}, {
Name: "other",
Owner: "[email protected]",
UUID: env3UUID,
}, {
Name: "other",
Owner: "[email protected]",
UUID: env4UUID,
}}
s.api = &fakeEnvMgrAPIClient{envs: envs}
s.creds = configstore.APICredentials{User: "tester", Password: "password"}
s.endpoint = configstore.APIEndpoint{
Addresses: []string{"127.0.0.1:12345"},
Hostnames: []string{"localhost:12345"},
CACert: testing.CACert,
ServerUUID: serverUUID,
}
}