示例#1
0
func (s *ChangePasswordCommandSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		args        []string
		user        string
		errorString string
	}{
		{
		// no args is fine
		}, {
			args: []string{"foobar"},
			user: "******",
		}, {
			args:        []string{"--foobar"},
			errorString: "flag provided but not defined: --foobar",
		}, {
			args:        []string{"foobar", "extra"},
			errorString: `unrecognized args: \["extra"\]`,
		},
	} {
		c.Logf("test %d", i)
		wrappedCommand, command := user.NewChangePasswordCommandForTest(nil, s.store)
		err := coretesting.InitCommand(wrappedCommand, test.args)
		if test.errorString == "" {
			c.Check(command.User, gc.Equals, test.user)
		} else {
			c.Check(err, gc.ErrorMatches, test.errorString)
		}
	}
}
示例#2
0
func (s *ChangePasswordCommandSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	changePasswordCommand, _ := user.NewChangePasswordCommandForTest(s.mockAPI, s.store)
	ctx := coretesting.Context(c)
	ctx.Stdin = strings.NewReader("sekrit\nsekrit\n")
	err := coretesting.InitCommand(changePasswordCommand, args)
	if err != nil {
		return ctx, err
	}
	return ctx, changePasswordCommand.Run(ctx)
}
示例#3
0
func (s *ChangePasswordCommandSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		args        []string
		user        string
		outPath     string
		generate    bool
		errorString string
	}{
		{
		// no args is fine
		}, {
			args:     []string{"--generate"},
			generate: true,
		}, {
			args:     []string{"foobar"},
			user:     "******",
			generate: true,
			outPath:  "foobar.server",
		}, {
			args:     []string{"foobar", "--generate"},
			user:     "******",
			generate: true,
			outPath:  "foobar.server",
		}, {
			args:     []string{"foobar", "--output", "somefile"},
			user:     "******",
			generate: true,
			outPath:  "somefile",
		}, {
			args:        []string{"--foobar"},
			errorString: "flag provided but not defined: --foobar",
		}, {
			args:        []string{"foobar", "extra"},
			errorString: `unrecognized args: \["extra"\]`,
		}, {
			args:        []string{"--output", "somefile"},
			errorString: "output is only a valid option when changing another user's password",
		},
	} {
		c.Logf("test %d", i)
		wrappedCommand, command := user.NewChangePasswordCommandForTest(nil, nil)
		err := testing.InitCommand(wrappedCommand, test.args)
		if test.errorString == "" {
			c.Check(command.User, gc.Equals, test.user)
			c.Check(command.OutPath, gc.Equals, test.outPath)
			c.Check(command.Generate, gc.Equals, test.generate)
		} else {
			c.Check(err, gc.ErrorMatches, test.errorString)
		}
	}
}
示例#4
0
func (s *ChangePasswordCommandSuite) run(c *gc.C, args ...string) (*cmd.Context, *juju.NewAPIConnectionParams, error) {
	var argsOut juju.NewAPIConnectionParams
	newAPIConnection := func(args juju.NewAPIConnectionParams) (api.Connection, error) {
		argsOut = args
		return mockAPIConnection{}, nil
	}
	changePasswordCommand, _ := user.NewChangePasswordCommandForTest(
		newAPIConnection, s.mockAPI, s.store,
	)
	ctx := coretesting.Context(c)
	ctx.Stdin = strings.NewReader("sekrit\nsekrit\n")
	err := coretesting.InitCommand(changePasswordCommand, args)
	if err != nil {
		return ctx, nil, err
	}
	return ctx, &argsOut, changePasswordCommand.Run(ctx)
}
示例#5
0
func (s *ChangePasswordCommandSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	changePasswordCommand, _ := user.NewChangePasswordCommandForTest(s.mockAPI, s.mockEnvironInfo)
	return testing.RunCommand(c, changePasswordCommand, args...)
}