func (*SwitchSimpleSuite) TestSettingWritesFile(c *gc.C) { testing.WriteEnvironments(c, testing.MultipleEnvConfig) context, err := testing.RunCommand(c, newSwitchCommand(), "erewhemos-2") c.Assert(err, jc.ErrorIsNil) c.Assert(testing.Stderr(context), gc.Equals, "-> erewhemos-2\n") currentEnv, err := modelcmd.ReadCurrentModel() c.Assert(err, jc.ErrorIsNil) c.Assert(currentEnv, gc.Equals, "erewhemos-2") }
func (s *BootstrapSuite) TestBootstrapSetsCurrentModel(c *gc.C) { const envName = "devenv" s.patchVersionAndSeries(c, envName) coretesting.WriteEnvironments(c, coretesting.MultipleEnvConfig) ctx, err := coretesting.RunCommand(c, newBootstrapCommand(), "-m", "devenv", "--auto-upgrade") c.Assert(coretesting.Stderr(ctx), jc.Contains, "-> devenv") currentEnv, err := modelcmd.ReadCurrentModel() c.Assert(err, jc.ErrorIsNil) c.Assert(currentEnv, gc.Equals, "devenv") }
func (*jenvSuite) TestSuccess(c *gc.C) { // Create a jenv file. contents := makeJenvContents("who", "Secret!", "model-UUID", testing.CACert, "1.2.3.4:17070") f := openJenvFile(c, contents) defer f.Close() // Import the newly created jenv file. jenvCmd := &model.JenvCommand{} ctx, err := testing.RunCommand(c, jenvCmd, f.Name()) c.Assert(err, jc.ErrorIsNil) // The jenv file has been properly imported. assertJenvContents(c, contents, "testing") // The default environment is now the newly imported one, and the output // reflects the change. currEnv, err := modelcmd.ReadCurrentModel() c.Assert(err, jc.ErrorIsNil) c.Assert(currEnv, gc.Equals, "testing") c.Assert(testing.Stdout(ctx), gc.Equals, "erewhemos -> testing\n") // Trying to import the jenv with the same name a second time raises an // error. jenvCmd = &model.JenvCommand{} ctx, err = testing.RunCommand(c, jenvCmd, f.Name()) c.Assert(err, gc.ErrorMatches, `an model named "testing" already exists: you can provide a second parameter to rename the model`) // Overriding the environment name solves the problem. jenvCmd = &model.JenvCommand{} ctx, err = testing.RunCommand(c, jenvCmd, f.Name(), "another") c.Assert(err, jc.ErrorIsNil) assertJenvContents(c, contents, "another") currEnv, err = modelcmd.ReadCurrentModel() c.Assert(err, jc.ErrorIsNil) c.Assert(currEnv, gc.Equals, "another") c.Assert(testing.Stdout(ctx), gc.Equals, "testing -> another\n") }
func (s *UseModelSuite) TestUseEnvAlreadyExistingSameEnv(c *gc.C) { s.makeLocalEnvironment(c, "unique", "some-uuid", "tester") ctx, err := s.run(c, "unique") c.Assert(err, gc.IsNil) message := strings.TrimSpace(testing.Stderr(ctx)) lines := strings.Split(message, "\n") c.Assert(lines, gc.HasLen, 2) expected := `You already have model details for "unique" cached locally.` c.Assert(lines[0], gc.Equals, expected) c.Assert(lines[1], gc.Equals, `fake (controller) -> unique`) current, err := modelcmd.ReadCurrentModel() c.Assert(err, gc.IsNil) c.Assert(current, gc.Equals, "unique") }
func (s *UseModelSuite) assertCurrentModel(c *gc.C, name, uuid string) { current, err := modelcmd.ReadCurrentModel() c.Assert(err, gc.IsNil) c.Assert(current, gc.Equals, name) store, err := configstore.Default() c.Assert(err, gc.IsNil) info, err := store.ReadInfo(name) c.Assert(err, gc.IsNil) c.Assert(info.APIEndpoint(), jc.DeepEquals, configstore.APIEndpoint{ Addresses: []string{"127.0.0.1:12345"}, Hostnames: []string{"localhost:12345"}, CACert: testing.CACert, ModelUUID: uuid, ServerUUID: serverUUID, }) c.Assert(info.APICredentials(), jc.DeepEquals, s.creds) }
func (*jenvSuite) TestSuccessCustomEnvironmentName(c *gc.C) { // Create a jenv file. contents := makeValidJenvContents() f := openJenvFile(c, contents) defer f.Close() // Import the newly created jenv file with a customized name. jenvCmd := &model.JenvCommand{} ctx, err := testing.RunCommand(c, jenvCmd, f.Name(), "my-env") c.Assert(err, jc.ErrorIsNil) // The jenv file has been properly imported. assertJenvContents(c, contents, "my-env") // The default environment is now the newly imported one, and the output // reflects the change. currEnv, err := modelcmd.ReadCurrentModel() c.Assert(err, jc.ErrorIsNil) c.Assert(currEnv, gc.Equals, "my-env") c.Assert(testing.Stdout(ctx), gc.Equals, "erewhemos -> my-env\n") }
func (s *filesSuite) assertCurrentModel(c *gc.C, environmentName string) { current, err := modelcmd.ReadCurrentModel() c.Assert(err, jc.ErrorIsNil) c.Assert(current, gc.Equals, environmentName) }