示例#1
0
func (s *RemoveUserSuite) TestRemoveUser(c *gc.C) {
	_, err := testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "password"})
	c.Assert(err, gc.IsNil)

	_, err = testing.RunCommand(c, &RemoveUserCommand{}, []string{"foobar"})
	c.Assert(err, gc.IsNil)
}
示例#2
0
func (s *AddUserSuite) TestAddUser(c *gc.C) {

	_, err := testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "password"})
	c.Assert(err, gc.IsNil)

	_, err = testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "newpassword"})
	c.Assert(err, gc.ErrorMatches, "Failed to create user: user already exists")
}
示例#3
0
func (s *SetEnvironmentSuite) TestChangeAsCommandPair(c *gc.C) {
	_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"default-series=raring"})
	c.Assert(err, gc.IsNil)

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

	c.Assert(output, gc.Equals, "raring")
}
示例#4
0
func (*SwitchSimpleSuite) TestSettingWritesFile(c *gc.C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"erewhemos-2"})
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "erewhemos -> erewhemos-2\n")
	c.Assert(envcmd.ReadCurrentEnvironment(), gc.Equals, "erewhemos-2")
}
示例#5
0
func (*SwitchSimpleSuite) TestListEnvironmentsOSJujuEnvSet(c *gc.C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	os.Setenv("JUJU_ENV", "using-env")
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"--list"})
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, expectedEnvironments)
}
示例#6
0
文件: run_test.go 项目: jameinel/core
func (s *RunSuite) TestAllMachines(c *gc.C) {
	mock := s.setupMockAPI()
	mock.setMachinesAlive("0", "1")
	response0 := mockResponse{
		stdout:    "megatron\n",
		machineId: "0",
	}
	response1 := mockResponse{
		error:     "command timed out",
		machineId: "1",
	}
	mock.setResponse("0", response0)

	unformatted := ConvertRunResults([]params.RunResult{
		makeRunResult(response0),
		makeRunResult(response1),
	})

	jsonFormatted, err := cmd.FormatJson(unformatted)
	c.Assert(err, gc.IsNil)

	context, err := testing.RunCommand(c, &RunCommand{}, []string{
		"--format=json", "--all", "hostname",
	})
	c.Assert(err, gc.IsNil)

	c.Check(testing.Stdout(context), gc.Equals, string(jsonFormatted)+"\n")
}
示例#7
0
func (*SwitchSimpleSuite) TestShowsJujuEnv(c *gc.C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	os.Setenv("JUJU_ENV", "using-env")
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "using-env\n")
}
示例#8
0
文件: run_test.go 项目: jameinel/core
func (s *RunSuite) TestRunForMachineAndUnit(c *gc.C) {
	mock := s.setupMockAPI()
	machineResponse := mockResponse{
		stdout:    "megatron\n",
		machineId: "0",
	}
	unitResponse := mockResponse{
		stdout:    "bumblebee",
		machineId: "1",
		unitId:    "unit/0",
	}
	mock.setResponse("0", machineResponse)
	mock.setResponse("unit/0", unitResponse)

	unformatted := ConvertRunResults([]params.RunResult{
		makeRunResult(machineResponse),
		makeRunResult(unitResponse),
	})

	jsonFormatted, err := cmd.FormatJson(unformatted)
	c.Assert(err, gc.IsNil)

	context, err := testing.RunCommand(c, &RunCommand{}, []string{
		"--format=json", "--machine=0", "--unit=unit/0", "hostname",
	})
	c.Assert(err, gc.IsNil)

	c.Check(testing.Stdout(context), gc.Equals, string(jsonFormatted)+"\n")
}
示例#9
0
func (s *retryProvisioningSuite) TestResolved(c *gc.C) {
	m, err := s.State.AddOneMachine(state.MachineTemplate{
		Series: "quantal",
		Jobs:   []state.MachineJob{state.JobManageEnviron},
	})
	c.Assert(err, gc.IsNil)
	err = m.SetStatus(params.StatusError, "broken", nil)
	c.Assert(err, gc.IsNil)
	_, err = s.State.AddOneMachine(state.MachineTemplate{
		Series: "quantal",
		Jobs:   []state.MachineJob{state.JobHostUnits},
	})
	c.Assert(err, gc.IsNil)

	for i, t := range resolvedMachineTests {
		c.Logf("test %d: %v", i, t.args)
		context, err := testing.RunCommand(c, &RetryProvisioningCommand{}, t.args)
		if t.err != "" {
			c.Check(err, gc.ErrorMatches, t.err)
			continue
		} else {
			c.Check(err, gc.IsNil)
		}
		output := testing.Stderr(context)
		stripped := strings.Replace(output, "\n", "", -1)
		c.Check(stripped, gc.Equals, t.stdErr)
		if t.args[0] == "0" {
			status, info, data, err := m.Status()
			c.Check(err, gc.IsNil)
			c.Check(status, gc.Equals, params.StatusError)
			c.Check(info, gc.Equals, "broken")
			c.Check(data["transient"], jc.IsTrue)
		}
	}
}
示例#10
0
func (s *UnsetEnvironmentSuite) TestUnsetEnvironment(c *gc.C) {
	for _, t := range unsetEnvTests {
		c.Logf("testing unset-env %v", t.args)
		s.initConfig(c)
		_, err := testing.RunCommand(c, &UnsetEnvironmentCommand{}, t.args)
		if t.err != "" {
			c.Assert(err, gc.ErrorMatches, t.err)
		} else {
			c.Assert(err, gc.IsNil)
		}
		if len(t.expected)+len(t.unexpected) != 0 {
			stateConfig, err := s.State.EnvironConfig()
			c.Assert(err, gc.IsNil)
			for k, v := range t.expected {
				vstate, ok := stateConfig.AllAttrs()[k]
				c.Assert(ok, jc.IsTrue)
				c.Assert(vstate, gc.Equals, v)
			}
			for _, k := range t.unexpected {
				_, ok := stateConfig.AllAttrs()[k]
				c.Assert(ok, jc.IsFalse)
			}
		}
	}
}
示例#11
0
func (s *SetEnvironmentSuite) TestChangeBooleanAttribute(c *gc.C) {
	_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"ssl-hostname-verification=false"})
	c.Assert(err, gc.IsNil)

	stateConfig, err := s.State.EnvironConfig()
	c.Assert(err, gc.IsNil)
	c.Assert(stateConfig.SSLHostnameVerification(), gc.Equals, false)
}
示例#12
0
func (s *DebugLogSuite) TestLogOutput(c *gc.C) {
	s.PatchValue(&getDebugLogAPI, func(envName string) (DebugLogAPI, error) {
		return &fakeDebugLogAPI{log: "this is the log output"}, nil
	})
	ctx, err := testing.RunCommand(c, &DebugLogCommand{}, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "this is the log output")
}
示例#13
0
func (*SwitchSimpleSuite) TestCurrentEnvironmentHasPrecidence(c *gc.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, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "fubar\n")
}
示例#14
0
func (s *AddUserSuite) TestJenvJsonFileOutput(c *gc.C) {
	expected := `{"User":"******","Password":"******","state-servers":null,"ca-cert":""}
`
	ctx, err := testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "password", "--format", "json"})
	c.Assert(err, gc.IsNil)
	stdout := ctx.Stdout.(*bytes.Buffer).String()
	c.Assert(stdout, gc.DeepEquals, expected)
}
示例#15
0
func (s *SetEnvironmentSuite) TestImmutableConfigValues(c *gc.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 [\"]?%v[\"]?", name, value)
		c.Assert(err, gc.ErrorMatches, errorPattern)
	}
}
示例#16
0
func (s *destroyEnvSuite) TestDestroyEnvironmentCommandEmptyJenv(c *gc.C) {
	_, err := s.ConfigStore.CreateInfo("emptyenv")
	c.Assert(err, gc.IsNil)

	context, err := coretesting.RunCommand(c, new(DestroyEnvironmentCommand), []string{"-e", "emptyenv"})
	c.Assert(err, gc.IsNil)

	c.Assert(coretesting.Stderr(context), gc.Equals, "removing empty environment file\n")
}
示例#17
0
文件: run_test.go 项目: jameinel/core
func (s *RunTestSuite) TestMissingSocket(c *gc.C) {
	s.PatchValue(&AgentDir, c.MkDir())
	testAgentDir := filepath.Join(AgentDir, "foo")
	err := os.Mkdir(testAgentDir, 0755)
	c.Assert(err, gc.IsNil)

	_, err = testing.RunCommand(c, &RunCommand{}, []string{"foo", "bar"})
	c.Assert(err, gc.ErrorMatches, `dial unix .*/run.socket: no such file or directory`)
}
示例#18
0
func (s *AddUserSuite) TestGeneratePassword(c *gc.C) {
	ctx, err := testing.RunCommand(c, &AddUserCommand{}, []string{"foobar"})
	c.Assert(err, gc.IsNil)
	stdout := ctx.Stdout.(*bytes.Buffer).Bytes()
	var d map[string]interface{}
	err = goyaml.Unmarshal(stdout, &d)
	c.Assert(err, gc.IsNil)
	c.Assert(d["user"], gc.DeepEquals, "foobar")
}
示例#19
0
文件: run_test.go 项目: jameinel/core
func (s *RunTestSuite) TestNoContext(c *gc.C) {
	s.PatchValue(&LockDir, c.MkDir())
	s.PatchValue(&AgentDir, c.MkDir())

	ctx, err := testing.RunCommand(c, &RunCommand{}, []string{"--no-context", "echo done"})
	c.Assert(err, jc.Satisfies, cmd.IsRcPassthroughError)
	c.Assert(err, gc.ErrorMatches, "subprocess encountered error code 0")
	c.Assert(testing.Stdout(ctx), gc.Equals, "done\n")
}
示例#20
0
func (*SwitchSimpleSuite) TestJujuEnvOverCurrentEnvironment(c *gc.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, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "using-env\n")
}
示例#21
0
func (s *ImportKeySuite) TestImportKeys(c *gc.C) {
	key1 := sshtesting.ValidKeyOne.Key + " user@host"
	s.setAuthorizedKeys(c, key1)

	context, err := coretesting.RunCommand(c, &ImportKeysCommand{}, []string{"lp:validuser", "invalid-key"})
	c.Assert(err, gc.IsNil)
	c.Assert(coretesting.Stderr(context), gc.Matches, `cannot import key id "invalid-key".*\n`)
	s.assertEnvironKeys(c, key1, sshtesting.ValidKeyThree.Key)
}
示例#22
0
func (s *RelationSetSuite) TestRunDeprecationWarning(c *gc.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, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "")
	c.Assert(testing.Stderr(ctx), gc.Equals, "--format flag deprecated for command \"relation-set\"")
}
示例#23
0
文件: run_test.go 项目: jameinel/core
func (s *RunTestSuite) TestRunning(c *gc.C) {
	loggo.GetLogger("worker.uniter").SetLogLevel(loggo.TRACE)
	s.runListenerForAgent(c, "foo")

	ctx, err := testing.RunCommand(c, &RunCommand{}, []string{"foo", "bar"})
	c.Check(cmd.IsRcPassthroughError(err), jc.IsTrue)
	c.Assert(err, gc.ErrorMatches, "subprocess encountered error code 42")
	c.Assert(testing.Stdout(ctx), gc.Equals, "bar stdout")
	c.Assert(testing.Stderr(ctx), gc.Equals, "bar stderr")
}
示例#24
0
func (s *UpgradeJujuSuite) TestUpgradeJujuWithRealUpload(c *gc.C) {
	s.Reset(c)
	_, err := coretesting.RunCommand(c, &UpgradeJujuCommand{}, []string{"--upload-tools"})
	c.Assert(err, gc.IsNil)
	vers := version.Current
	vers.Build = 1
	tools, err := envtools.FindInstanceTools(s.Conn.Environ, vers.Number, vers.Series, &vers.Arch)
	c.Assert(err, gc.IsNil)
	c.Assert(len(tools), gc.Equals, 1)
}
示例#25
0
func (s *DeploySuite) TestUpgradeReportsDeprecated(c *gc.C) {
	coretesting.Charms.ClonedDirPath(s.SeriesPath, "dummy")
	ctx, err := coretesting.RunCommand(c, &DeployCommand{}, []string{"local:dummy", "-u"})
	c.Assert(err, gc.IsNil)

	c.Assert(coretesting.Stdout(ctx), gc.Equals, "")
	output := strings.Split(coretesting.Stderr(ctx), "\n")
	c.Check(output[0], gc.Matches, `Added charm ".*" to the environment.`)
	c.Check(output[1], gc.Equals, "--upgrade (or -u) is deprecated and ignored; charms are always deployed with a unique revision.")
}
示例#26
0
func (s *AddKeySuite) TestAddKey(c *gc.C) {
	key1 := sshtesting.ValidKeyOne.Key + " user@host"
	s.setAuthorizedKeys(c, key1)

	key2 := sshtesting.ValidKeyTwo.Key + " another@host"
	context, err := coretesting.RunCommand(c, &AddKeysCommand{}, []string{key2, "invalid-key"})
	c.Assert(err, gc.IsNil)
	c.Assert(coretesting.Stderr(context), gc.Matches, `cannot add key "invalid-key".*\n`)
	s.assertEnvironKeys(c, key1, key2)
}
示例#27
0
func (s *AddUserSuite) TestJenvJsonOutput(c *gc.C) {
	expected := `{"User":"******","Password":"******","state-servers":null,"ca-cert":""}
`
	tempFile, err := ioutil.TempFile("", "adduser-test")
	tempFile.Close()
	c.Assert(err, gc.IsNil)
	_, err = testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "password", "-o", tempFile.Name(), "--format", "json"})
	c.Assert(err, gc.IsNil)
	data, err := ioutil.ReadFile(tempFile.Name())
	c.Assert(string(data), gc.DeepEquals, expected)
}
示例#28
0
func (s *ListKeysSuite) TestListFullKeys(c *gc.C) {
	key1 := sshtesting.ValidKeyOne.Key + " user@host"
	key2 := sshtesting.ValidKeyTwo.Key + " another@host"
	s.setAuthorizedKeys(c, key1, key2)

	context, err := coretesting.RunCommand(c, &ListKeysCommand{}, []string{"--full"})
	c.Assert(err, gc.IsNil)
	output := strings.TrimSpace(coretesting.Stdout(context))
	c.Assert(err, gc.IsNil)
	c.Assert(output, gc.Matches, "Keys for user admin:\n.*user@host\n.*another@host")
}
示例#29
0
func (s *ImportKeySuite) TestImportKeyNonDefaultUser(c *gc.C) {
	key1 := sshtesting.ValidKeyOne.Key + " user@host"
	s.setAuthorizedKeys(c, key1)
	_, err := s.State.AddUser("fred", "password")
	c.Assert(err, gc.IsNil)

	context, err := coretesting.RunCommand(c, &ImportKeysCommand{}, []string{"--user", "fred", "lp:validuser"})
	c.Assert(err, gc.IsNil)
	c.Assert(coretesting.Stderr(context), gc.Equals, "")
	s.assertEnvironKeys(c, key1, sshtesting.ValidKeyThree.Key)
}
示例#30
0
func (s *DeleteKeySuite) TestDeleteKeys(c *gc.C) {
	key1 := sshtesting.ValidKeyOne.Key + " user@host"
	key2 := sshtesting.ValidKeyTwo.Key + " another@host"
	s.setAuthorizedKeys(c, key1, key2)

	context, err := coretesting.RunCommand(
		c, &DeleteKeysCommand{}, []string{sshtesting.ValidKeyTwo.Fingerprint, "invalid-key"})
	c.Assert(err, gc.IsNil)
	c.Assert(coretesting.Stderr(context), gc.Matches, `cannot delete key id "invalid-key".*\n`)
	s.assertEnvironKeys(c, key1)
}