Exemplo n.º 1
0
func (s *SetEnvironmentSuite) TestChangeAsCommandPair(c *C) {
	_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"default-series=raring"})
	c.Assert(err, IsNil)

	context, err := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{"default-series"})
	c.Assert(err, IsNil)
	output := strings.TrimSpace(testing.Stdout(context))

	c.Assert(output, Equals, "raring")
}
Exemplo n.º 2
0
func runDebugLog(c *C, args ...string) (*DebugLogCommand, error) {
	cmd := &DebugLogCommand{
		sshCmd: &dummySSHCommand{},
	}
	_, err := testing.RunCommand(c, cmd, args)
	return cmd, err
}
Exemplo n.º 3
0
func (*SwitchSimpleSuite) TestSettingWritesFile(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"erewhemos-2"})
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Changed default environment from \"erewhemos\" to \"erewhemos-2\"\n")
	c.Assert(readCurrentEnvironment(), Equals, "erewhemos-2")
}
Exemplo n.º 4
0
func (*SwitchSimpleSuite) TestListEnvironments(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"--list"})
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Matches, "Current environment: \"erewhemos\"(.|\n)*")
	c.Assert(testing.Stdout(context), Matches, "(.|\n)*"+expectedEnvironments)
}
Exemplo n.º 5
0
func (*SwitchSimpleSuite) TestShowsJujuEnv(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	os.Setenv("JUJU_ENV", "using-env")
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Current environment: \"using-env\" (from JUJU_ENV)\n")
}
Exemplo n.º 6
0
func (s *SetEnvironmentSuite) TestChangeDefaultSeries(c *C) {
	_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"default-series=raring"})
	c.Assert(err, IsNil)

	stateConfig, err := s.State.EnvironConfig()
	c.Assert(err, IsNil)
	c.Assert(stateConfig.DefaultSeries(), Equals, "raring")
}
Exemplo n.º 7
0
func (s *SetEnvironmentSuite) TestImmutableConfigValues(c *C) {
	for name, value := range immutableConfigTests {
		param := fmt.Sprintf("%s=%s", name, value)
		_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{param})
		errorPattern := fmt.Sprintf("cannot change %s from .* to %q", name, value)
		c.Assert(err, ErrorMatches, errorPattern)
	}
}
Exemplo n.º 8
0
func (*SwitchSimpleSuite) TestCurrentEnvironmentHasPrecidence(c *C) {
	home := testing.MakeFakeHome(c, testing.MultipleEnvConfig)
	defer home.Restore()
	home.AddFiles(c, []testing.TestFile{{".juju/current-environment", "fubar"}})
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Current environment: \"fubar\"\n")
}
Exemplo n.º 9
0
func (*SwitchSimpleSuite) TestJujuEnvOverCurrentEnvironment(c *C) {
	home := testing.MakeFakeHome(c, testing.MultipleEnvConfig)
	defer home.Restore()
	home.AddFiles(c, []testing.TestFile{{".juju/current-environment", "fubar"}})
	os.Setenv("JUJU_ENV", "using-env")
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Current environment: \"using-env\" (from JUJU_ENV)\n")
}
Exemplo n.º 10
0
func (s *RelationSetSuite) TestRunDeprecationWarning(c *C) {
	hctx := s.GetHookContext(c, 0, "")
	com, _ := jujuc.NewCommand(hctx, "relation-set")
	// The rel= is needed to make this a valid command.
	ctx, err := testing.RunCommand(c, com, []string{"--format", "foo", "rel="})

	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(ctx), Equals, "")
	c.Assert(testing.Stderr(ctx), Equals, "--format flag deprecated for command \"relation-set\"")
}
Exemplo n.º 11
0
func (s *SetEnvironmentSuite) TestChangeMultipleValues(c *C) {
	_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"default-series=spartan", "broken=nope", "secret=sekrit"})
	c.Assert(err, IsNil)

	stateConfig, err := s.State.EnvironConfig()
	c.Assert(err, IsNil)
	attrs := stateConfig.AllAttrs()
	c.Assert(attrs["default-series"].(string), Equals, "spartan")
	c.Assert(attrs["broken"].(string), Equals, "nope")
	c.Assert(attrs["secret"].(string), Equals, "sekrit")
}
Exemplo n.º 12
0
func (s *GetEnvironmentSuite) TestAllValues(c *C) {

	context, _ := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{})
	output := strings.TrimSpace(testing.Stdout(context))

	// Make sure that all the environment keys are there.
	any := "(.|\n)*" // because . doesn't match new lines.
	for key := range s.Conn.Environ.Config().AllAttrs() {
		c.Assert(output, Matches, fmt.Sprintf("%s%s: %s", any, key, any))
	}
}
Exemplo n.º 13
0
func (s *UpgradeJujuSuite) TestUpgradeJujuWithRealUpload(c *C) {
	s.Reset(c)
	_, err := coretesting.RunCommand(c, &UpgradeJujuCommand{}, []string{"--upload-tools"})
	c.Assert(err, IsNil)
	vers := version.Current
	vers.Build = 1
	name := tools.StorageName(vers)
	r, err := s.Conn.Environ.Storage().Get(name)
	c.Assert(err, IsNil)
	r.Close()
}
Exemplo n.º 14
0
func (s *GetEnvironmentSuite) TestSingleValue(c *C) {

	for _, t := range singleValueTests {
		context, err := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{t.key})
		if t.err != "" {
			c.Assert(err, ErrorMatches, t.err)
		} else {
			output := strings.TrimSpace(testing.Stdout(context))
			c.Assert(err, IsNil)
			c.Assert(output, Equals, t.output)
		}
	}
}
Exemplo n.º 15
0
func (s *JujuLogSuite) TestLogDeprecation(c *C) {
	com := newJujuLogCommand(c)
	ctx, err := testing.RunCommand(c, com, []string{"--format", "foo", "msg"})
	c.Assert(err, IsNil)
	c.Assert(testing.Stderr(ctx), Equals, "--format flag deprecated for command \"juju-log\"")
}
Exemplo n.º 16
0
func runUpgradeCharm(c *C, args ...string) error {
	_, err := testing.RunCommand(c, &UpgradeCharmCommand{}, args)
	return err
}
Exemplo n.º 17
0
func runSyncToolsCommand(c *C, args ...string) (*cmd.Context, error) {
	return testing.RunCommand(c, &SyncToolsCommand{}, args)
}
Exemplo n.º 18
0
func runAddUnit(c *C, args ...string) error {
	_, err := testing.RunCommand(c, &AddUnitCommand{}, args)
	return err
}
Exemplo n.º 19
0
func (*SwitchSimpleSuite) TestNoEnvironment(c *C) {
	defer testing.MakeEmptyFakeHome(c).Restore()
	_, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, ErrorMatches, "couldn't read the environment.")
}
Exemplo n.º 20
0
func (*SwitchSimpleSuite) TestSettingToUnknown(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	_, err := testing.RunCommand(c, &SwitchCommand{}, []string{"unknown"})
	c.Assert(err, ErrorMatches, `"unknown" is not a name of an existing defined environment`)
}
Exemplo n.º 21
0
func runDestroyRelation(c *C, args ...string) error {
	_, err := testing.RunCommand(c, &DestroyRelationCommand{}, args)
	return err
}
Exemplo n.º 22
0
func runDestroyService(c *C, args ...string) error {
	_, err := testing.RunCommand(c, &DestroyServiceCommand{}, args)
	return err
}
Exemplo n.º 23
0
func runResolved(c *C, args []string) error {
	_, err := testing.RunCommand(c, &ResolvedCommand{}, args)
	return err
}
Exemplo n.º 24
0
func runUnexpose(c *C, args ...string) error {
	_, err := testing.RunCommand(c, &UnexposeCommand{}, args)
	return err
}
Exemplo n.º 25
0
func (*SwitchSimpleSuite) TestShowsDefault(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Current environment: \"erewhemos\"\n")
}
Exemplo n.º 26
0
func (*SwitchSimpleSuite) TestNoDefault(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfigNoDefault).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Current environment: <not specified>\n")
}
Exemplo n.º 27
0
func (s *GetEnvironmentSuite) TestTooManyArgs(c *C) {
	_, err := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{"name", "type"})
	c.Assert(err, ErrorMatches, `unrecognized args: \["type"\]`)
}
Exemplo n.º 28
0
func (*SwitchSimpleSuite) TestSettingWhenJujuEnvSet(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	os.Setenv("JUJU_ENV", "using-env")
	_, err := testing.RunCommand(c, &SwitchCommand{}, []string{"erewhemos-2"})
	c.Assert(err, ErrorMatches, `Cannot switch when JUJU_ENV is overriding the environment \(set to "using-env"\)`)
}
Exemplo n.º 29
0
func runAddMachine(c *C, args ...string) error {
	_, err := testing.RunCommand(c, &AddMachineCommand{}, args)
	return err
}
Exemplo n.º 30
0
func (*SwitchSimpleSuite) TestTooManyParams(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	_, err := testing.RunCommand(c, &SwitchCommand{}, []string{"foo", "bar"})
	c.Assert(err, ErrorMatches, `unrecognized args: ."bar".`)
}