~gz/juju-core/trunk

« back to all changes in this revision

Viewing changes to cmd/juju/main_test.go

[r=rogpeppe] all: standardise gocheck imports, A-D

This is an automated change to use "gc" for gocheck
imports throughout. To avoid clogging Rietveld, I've
split it up into three parts - this is the first.

https://codereview.appspot.com/12940044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
        stdtesting "testing"
16
16
 
17
17
        "launchpad.net/gnuflag"
18
 
        . "launchpad.net/gocheck"
 
18
        gc "launchpad.net/gocheck"
19
19
        "launchpad.net/loggo"
20
20
 
21
21
        "launchpad.net/juju-core/cmd"
32
32
 
33
33
type MainSuite struct{}
34
34
 
35
 
var _ = Suite(&MainSuite{})
 
35
var _ = gc.Suite(&MainSuite{})
36
36
 
37
37
var (
38
38
        flagRunMain = flag.Bool("run-main", false, "Run the application's main function for recursive testing")
46
46
        }
47
47
}
48
48
 
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()
54
54
        if exit != 0 {
55
 
                c.Assert(err, ErrorMatches, fmt.Sprintf("exit status %d", exit))
 
55
                c.Assert(err, gc.ErrorMatches, fmt.Sprintf("exit status %d", exit))
56
56
        }
57
57
        return string(output)
58
58
}
75
75
        return helpText(&SyncToolsCommand{}, "juju sync-tools")
76
76
}
77
77
 
78
 
func (s *MainSuite) TestTearDown(c *C) {
 
78
func (s *MainSuite) TestTearDown(c *gc.C) {
79
79
        loggo.ResetLoggers()
80
80
}
81
81
 
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
166
166
        } {
167
167
                c.Logf("test %d: %s", i, t.summary)
168
168
                out := badrun(c, t.code, t.args...)
169
 
                c.Assert(out, Equals, t.out)
 
169
                c.Assert(out, gc.Equals, t.out)
170
170
        }
171
171
}
172
172
 
180
180
 
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, IsNil)
 
186
        c.Assert(err, gc.IsNil)
187
187
        return fmt.Sprintf("environment configuration has no admin-secret")
188
188
}
189
189
 
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, IsNil)
 
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)
201
201
}
202
202
 
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, IsNil)
 
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)
214
214
}
215
215
 
216
216
var commandNames = []string{
258
258
        "version",
259
259
}
260
260
 
261
 
func (s *MainSuite) TestHelpCommands(c *C) {
 
261
func (s *MainSuite) TestHelpCommands(c *gc.C) {
262
262
        // Check that we have correctly registered all the commands
263
263
        // by checking the help output.
264
264
        defer config.SetJujuHome(config.SetJujuHome(c.MkDir()))
273
273
                names = append(names, f[0])
274
274
        }
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)
277
277
}
278
278
 
279
279
var topicNames = []string{
289
289
        "topics",
290
290
}
291
291
 
292
 
func (s *MainSuite) TestHelpTopics(c *C) {
 
292
func (s *MainSuite) TestHelpTopics(c *gc.C) {
293
293
        // Check that we have correctly registered all the topics
294
294
        // by checking the help output.
295
295
        defer config.SetJujuHome(config.SetJujuHome(c.MkDir()))
304
304
                names = append(names, f[0])
305
305
        }
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)
308
308
}
309
309
 
310
310
var globalFlags = []string{
316
316
        "-v, --verbose .*",
317
317
}
318
318
 
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
325
325
 
326
326
These options may be used with any command, and may appear in front of any
327
327
command\.(.|\n)*`)
334
334
                }
335
335
                flags = append(flags, line)
336
336
        }
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])
340
340
        }
341
341
}