49
func badrun(c *C, exit int, args ...string) string {
49
func badrun(c *gc.C, exit int, args ...string) string {
50
50
localArgs := append([]string{"-test.run", "TestRunMain", "-run-main", "--", "juju"}, args...)
51
51
ps := exec.Command(os.Args[0], localArgs...)
52
52
ps.Env = append(os.Environ(), osenv.JujuHome+"="+config.JujuHome())
53
53
output, err := ps.CombinedOutput()
55
c.Assert(err, ErrorMatches, fmt.Sprintf("exit status %d", exit))
55
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("exit status %d", exit))
57
57
return string(output)
75
75
return helpText(&SyncToolsCommand{}, "juju sync-tools")
78
func (s *MainSuite) TestTearDown(c *C) {
78
func (s *MainSuite) TestTearDown(c *gc.C) {
79
79
loggo.ResetLoggers()
82
func (s *MainSuite) TestRunMain(c *C) {
82
func (s *MainSuite) TestRunMain(c *gc.C) {
83
83
defer testing.MakeSampleHome(c).Restore()
84
84
// The test array structure needs to be inline here as some of the
85
85
// expected values below use deployHelpText(). This constructs the deploy
181
181
// breakJuju writes a dummy environment with incomplete configuration.
182
182
// environMethod is called.
183
func breakJuju(c *C, environMethod string) (msg string) {
183
func breakJuju(c *gc.C, environMethod string) (msg string) {
184
184
path := config.JujuHomePath("environments.yaml")
185
185
err := ioutil.WriteFile(path, []byte(brokenConfig), 0666)
186
c.Assert(err, gc.IsNil)
187
187
return fmt.Sprintf("environment configuration has no admin-secret")
190
func (s *MainSuite) TestActualRunJujuArgsBeforeCommand(c *C) {
190
func (s *MainSuite) TestActualRunJujuArgsBeforeCommand(c *gc.C) {
191
191
defer testing.MakeFakeHomeNoEnvironments(c, "one").Restore()
192
192
// Check global args work when specified before command
193
193
msg := breakJuju(c, "Bootstrap")
194
194
logpath := filepath.Join(c.MkDir(), "log")
195
195
out := badrun(c, 1, "--log-file", logpath, "--verbose", "--debug", "bootstrap")
196
c.Assert(out, Equals, "error: "+msg+"\n")
196
c.Assert(out, gc.Equals, "error: "+msg+"\n")
197
197
content, err := ioutil.ReadFile(logpath)
198
c.Assert(err, gc.IsNil)
199
199
fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* command failed: %s\n`, msg)
200
c.Assert(string(content), Matches, fullmsg)
200
c.Assert(string(content), gc.Matches, fullmsg)
203
func (s *MainSuite) TestActualRunJujuArgsAfterCommand(c *C) {
203
func (s *MainSuite) TestActualRunJujuArgsAfterCommand(c *gc.C) {
204
204
defer testing.MakeFakeHomeNoEnvironments(c, "one").Restore()
205
205
// Check global args work when specified after command
206
206
msg := breakJuju(c, "Bootstrap")
207
207
logpath := filepath.Join(c.MkDir(), "log")
208
208
out := badrun(c, 1, "bootstrap", "--log-file", logpath, "--verbose", "--debug")
209
c.Assert(out, Equals, "error: "+msg+"\n")
209
c.Assert(out, gc.Equals, "error: "+msg+"\n")
210
210
content, err := ioutil.ReadFile(logpath)
211
c.Assert(err, gc.IsNil)
212
212
fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* command failed: %s\n`, msg)
213
c.Assert(string(content), Matches, fullmsg)
213
c.Assert(string(content), gc.Matches, fullmsg)
216
216
var commandNames = []string{
273
273
names = append(names, f[0])
275
275
// The names should be output in alphabetical order, so don't sort.
276
c.Assert(names, DeepEquals, commandNames)
276
c.Assert(names, gc.DeepEquals, commandNames)
279
279
var topicNames = []string{
304
304
names = append(names, f[0])
306
306
// The names should be output in alphabetical order, so don't sort.
307
c.Assert(names, DeepEquals, topicNames)
307
c.Assert(names, gc.DeepEquals, topicNames)
310
310
var globalFlags = []string{
316
316
"-v, --verbose .*",
319
func (s *MainSuite) TestHelpGlobalOptions(c *C) {
319
func (s *MainSuite) TestHelpGlobalOptions(c *gc.C) {
320
320
// Check that we have correctly registered all the topics
321
321
// by checking the help output.
322
322
defer config.SetJujuHome(config.SetJujuHome(c.MkDir()))
323
323
out := badrun(c, 0, "help", "global-options")
324
c.Assert(out, Matches, `Global Options
324
c.Assert(out, gc.Matches, `Global Options
326
326
These options may be used with any command, and may appear in front of any
327
327
command\.(.|\n)*`)
335
335
flags = append(flags, line)
337
c.Assert(len(flags), Equals, len(globalFlags))
337
c.Assert(len(flags), gc.Equals, len(globalFlags))
338
338
for i, line := range flags {
339
c.Assert(line, Matches, globalFlags[i])
339
c.Assert(line, gc.Matches, globalFlags[i])