func (s *UserAddCommandSuite) TestInit(c *gc.C) { for i, test := range []struct { args []string user string displayname string models string acl string outPath string errorString string }{{ errorString: "no username supplied", }, { args: []string{"foobar"}, user: "******", }, { args: []string{"foobar", "Foo Bar"}, user: "******", displayname: "Foo Bar", }, { args: []string{"foobar", "Foo Bar", "extra"}, errorString: `unrecognized args: \["extra"\]`, }, { args: []string{"foobar", "--models", "foo,bar", "--acl=read"}, user: "******", models: "foo,bar", acl: "read", }, { args: []string{"foobar", "--models", "baz", "--acl=write"}, user: "******", models: "baz", acl: "write", }} { c.Logf("test %d (%q)", i, test.args) wrappedCommand, command := user.NewAddCommandForTest(s.mockAPI, s.store, &mockModelApi{}) err := testing.InitCommand(wrappedCommand, test.args) if test.errorString == "" { c.Check(err, jc.ErrorIsNil) c.Check(command.User, gc.Equals, test.user) c.Check(command.DisplayName, gc.Equals, test.displayname) if len(test.models) > 0 { c.Check(command.ModelNames, gc.Equals, test.models) } if test.acl != "" { c.Check(command.ModelAccess, gc.Equals, test.acl) } } else { c.Check(err, gc.ErrorMatches, test.errorString) } } }
func (s *UserAddCommandSuite) TestInit(c *gc.C) { for i, test := range []struct { args []string user string displayname string outPath string errorString string }{ { errorString: "no username supplied", }, { args: []string{"foobar"}, user: "******", outPath: "foobar.server", }, { args: []string{"foobar", "Foo Bar"}, user: "******", displayname: "Foo Bar", outPath: "foobar.server", }, { args: []string{"foobar", "Foo Bar", "extra"}, errorString: `unrecognized args: \["extra"\]`, }, { args: []string{"foobar", "--output", "somefile"}, user: "******", outPath: "somefile", }, { args: []string{"foobar", "-o", "somefile"}, user: "******", outPath: "somefile", }, } { c.Logf("test %d", i) wrappedCommand, command := user.NewAddCommandForTest(s.mockAPI) err := testing.InitCommand(wrappedCommand, test.args) if test.errorString == "" { c.Check(command.User, gc.Equals, test.user) c.Check(command.DisplayName, gc.Equals, test.displayname) c.Check(command.OutPath, gc.Equals, test.outPath) } else { c.Check(err, gc.ErrorMatches, test.errorString) } } }
func (s *UserAddCommandSuite) run(c *gc.C, args ...string) (*cmd.Context, error) { addCommand, _ := user.NewAddCommandForTest(s.mockAPI, s.store, &mockModelApi{}) return testing.RunCommand(c, addCommand, args...) }