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: "user-admin@local", UUID: "test-env1-UUID", LastConnection: &last1, }, { Name: "test-env2", Owner: "user-admin@local", UUID: "test-env2-UUID", LastConnection: &last2, }, { Name: "test-env3", Owner: "user-admin@local", UUID: "test-env3-UUID", }, } s.api = &fakeEnvMgrAPIClient{envs: envs} s.creds = &configstore.APICredentials{User: "******", Password: "******"} }
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) }
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") }
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"`) }
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") }
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: "******", 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) }
func (s *removeBlocksSuite) SetUpTest(c *gc.C) { s.FakeJujuHomeSuite.SetUpTest(c) err := envcmd.WriteCurrentSystem("fake") c.Assert(err, jc.ErrorIsNil) s.api = &fakeRemoveBlocksAPI{} }
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") }
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") }
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") }
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 dummy-admin@local just now\n"+ "new-env dummy-admin@local never connected\n"+ "\n") }
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) }
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) }
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() }
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: "tester@local", UUID: "some-uuid", }, { Name: "test", Owner: "tester@local", UUID: env1UUID, }, { Name: "test", Owner: "bob@local", UUID: env2UUID, }, { Name: "other", Owner: "bob@local", UUID: env3UUID, }, { Name: "other", Owner: "bob@remote", UUID: env4UUID, }} s.api = &fakeEnvMgrAPIClient{envs: envs} s.creds = configstore.APICredentials{User: "******", Password: "******"} s.endpoint = configstore.APIEndpoint{ Addresses: []string{"127.0.0.1:12345"}, Hostnames: []string{"localhost:12345"}, CACert: testing.CACert, ServerUUID: serverUUID, } }
func (s *SystemCommandSuite) TestSystemCommandInitSystemFile(c *gc.C) { // If there is a current-system file, use that. err := envcmd.WriteCurrentSystem("fubar") c.Assert(err, jc.ErrorIsNil) testEnsureSystemName(c, "fubar") }
func (s *filesSuite) TestReadCurrentSystemSet(c *gc.C) { err := envcmd.WriteCurrentSystem("fubar") c.Assert(err, jc.ErrorIsNil) s.assertCurrentSystem(c, "fubar") }
func (*filesSuite) TestErrorWritingCurrentSystem(c *gc.C) { // Can't write a file over a directory. os.MkdirAll(envcmd.GetCurrentSystemFilePath(), 0777) err := envcmd.WriteCurrentSystem("fubar") c.Assert(err, gc.ErrorMatches, "unable to write to the system file: .*") }