Beispiel #1
0
func (s *AddMachineSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		args        []string
		series      string
		constraints string
		placement   string
		count       int
		errorString string
	}{
		{
			count: 1,
		}, {
			args:   []string{"--series", "some-series"},
			count:  1,
			series: "some-series",
		}, {
			args:  []string{"-n", "2"},
			count: 2,
		}, {
			args:      []string{"lxc"},
			count:     1,
			placement: "lxc:",
		}, {
			args:      []string{"lxc", "-n", "2"},
			count:     2,
			placement: "lxc:",
		}, {
			args:      []string{"lxc:4"},
			count:     1,
			placement: "lxc:4",
		}, {
			args:        []string{"--constraints", "mem=8G"},
			count:       1,
			constraints: "mem=8192M",
		}, {
			args:        []string{"--constraints", "container=lxc"},
			errorString: `container constraint "lxc" not allowed when adding a machine`,
		}, {
			args:      []string{"ssh:[email protected]"},
			count:     1,
			placement: "ssh:[email protected]",
		}, {
			args:      []string{"zone=us-east-1a"},
			count:     1,
			placement: "model-uuid:zone=us-east-1a",
		}, {
			args:      []string{"anything-here"},
			count:     1,
			placement: "model-uuid:anything-here",
		}, {
			args:        []string{"anything", "else"},
			errorString: `unrecognized args: \["else"\]`,
		}, {
			args:      []string{"something:special"},
			count:     1,
			placement: "something:special",
		},
	} {
		c.Logf("test %d", i)
		wrappedCommand, addCmd := machine.NewAddCommandForTest(s.fakeAddMachine, s.fakeMachineManager)
		err := testing.InitCommand(wrappedCommand, test.args)
		if test.errorString == "" {
			c.Check(err, jc.ErrorIsNil)
			c.Check(addCmd.Series, gc.Equals, test.series)
			c.Check(addCmd.Constraints.String(), gc.Equals, test.constraints)
			if addCmd.Placement != nil {
				c.Check(addCmd.Placement.String(), gc.Equals, test.placement)
			} else {
				c.Check("", gc.Equals, test.placement)
			}
			c.Check(addCmd.NumMachines, gc.Equals, test.count)
		} else {
			c.Check(err, gc.ErrorMatches, test.errorString)
		}
	}
}
Beispiel #2
0
func (s *AddMachineSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	add, _ := machine.NewAddCommandForTest(s.fakeAddMachine, s.fakeMachineManager)
	return testing.RunCommand(c, add, args...)
}