OLD | NEW |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "io/ioutil" | 4 "io/ioutil" |
5 "launchpad.net/gnuflag" | 5 "launchpad.net/gnuflag" |
6 . "launchpad.net/gocheck" | 6 . "launchpad.net/gocheck" |
7 "launchpad.net/juju-core/cmd" | 7 "launchpad.net/juju-core/cmd" |
8 ) | 8 ) |
9 | 9 |
10 type acCreator func() (cmd.Command, *AgentConf) | 10 type acCreator func() (cmd.Command, *AgentConf) |
11 | 11 |
12 func initCmd(c cmd.Command, args []string) error { | 12 func initCmd(c cmd.Command, args []string) error { |
13 f := gnuflag.NewFlagSet("", gnuflag.ContinueOnError) | 13 f := gnuflag.NewFlagSet("", gnuflag.ContinueOnError) |
14 f.SetOutput(ioutil.Discard) | 14 f.SetOutput(ioutil.Discard) |
15 return c.Init(f, args) | 15 return c.Init(f, args) |
16 } | 16 } |
17 | 17 |
18 // CheckAgentCommand is a utility function for verifying that common agent | 18 // CheckAgentCommand is a utility function for verifying that common agent |
19 // options are handled by a Command; it returns an instance of that | 19 // options are handled by a Command; it returns an instance of that |
20 // command pre-parsed with the always-required options and whatever others | 20 // command pre-parsed with the always-required options and whatever others |
21 // are necessary to allow parsing to succeed (specified in args). | 21 // are necessary to allow parsing to succeed (specified in args). |
22 func CheckAgentCommand(c *C, create acCreator, args []string) cmd.Command { | 22 func CheckAgentCommand(c *C, create acCreator, args []string) cmd.Command { |
23 com, _ := create() | 23 com, _ := create() |
24 err := initCmd(com, args) | 24 err := initCmd(com, args) |
25 » c.Assert(err, ErrorMatches, "--zookeeper-servers option must be set") | 25 » c.Assert(err, ErrorMatches, "--state-servers option must be set") |
26 » args = append(args, "--zookeeper-servers", "zk1:2181,zk2:2181") | 26 » args = append(args, "--state-servers", "st1:37017,st2:37017") |
27 | 27 |
28 com, conf := create() | 28 com, conf := create() |
29 c.Assert(initCmd(com, args), IsNil) | 29 c.Assert(initCmd(com, args), IsNil) |
30 » c.Assert(conf.StateInfo.Addrs, DeepEquals, []string{"zk1:2181", "zk2:218
1"}) | 30 » c.Assert(conf.StateInfo.Addrs, DeepEquals, []string{"st1:37017", "st2:37
017"}) |
31 c.Assert(conf.DataDir, Equals, "/var/lib/juju") | 31 c.Assert(conf.DataDir, Equals, "/var/lib/juju") |
32 args = append(args, "--data-dir", "jd") | 32 args = append(args, "--data-dir", "jd") |
33 | 33 |
34 com, conf = create() | 34 com, conf = create() |
35 c.Assert(initCmd(com, args), IsNil) | 35 c.Assert(initCmd(com, args), IsNil) |
36 » c.Assert(conf.StateInfo.Addrs, DeepEquals, []string{"zk1:2181", "zk2:218
1"}) | 36 » c.Assert(conf.StateInfo.Addrs, DeepEquals, []string{"st1:37017", "st2:37
017"}) |
37 c.Assert(conf.DataDir, Equals, "jd") | 37 c.Assert(conf.DataDir, Equals, "jd") |
38 return com | 38 return com |
39 } | 39 } |
40 | 40 |
41 // ParseAgentCommand is a utility function that inserts the always-required args | 41 // ParseAgentCommand is a utility function that inserts the always-required args |
42 // before parsing an agent command and returning the result. | 42 // before parsing an agent command and returning the result. |
43 func ParseAgentCommand(ac cmd.Command, args []string) error { | 43 func ParseAgentCommand(ac cmd.Command, args []string) error { |
44 common := []string{ | 44 common := []string{ |
45 » » "--zookeeper-servers", "zk:2181", | 45 » » "--state-servers", "st:37017", |
46 "--data-dir", "jd", | 46 "--data-dir", "jd", |
47 } | 47 } |
48 return initCmd(ac, append(common, args...)) | 48 return initCmd(ac, append(common, args...)) |
49 } | 49 } |
OLD | NEW |