~axwalk/juju-core/lp1303195-manual-ubuntuuser-bash

« back to all changes in this revision

Viewing changes to cmd/logging_test.go

  • Committer: Tim Penhey
  • Date: 2014-03-25 22:31:46 UTC
  • mto: This revision was merged to the branch mainline in revision 2479.
  • Revision ID: tim.penhey@canonical.com-20140325223146-tt2co7wy92k166o5
Move the methods to the command context.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
var _ = gc.Suite(&LogSuite{})
26
26
 
27
27
func (s *LogSuite) SetUpTest(c *gc.C) {
 
28
        s.CleanupSuite.SetUpTest(c)
28
29
        s.PatchEnvironment(osenv.JujuLoggingConfigEnvKey, "")
29
30
        s.AddCleanup(func(_ *gc.C) {
30
31
                loggo.ResetLoggers()
31
32
                loggo.ResetWriters()
32
 
                cmd.ResetCommandWriters()
33
33
        })
34
34
}
35
35
 
155
155
 
156
156
func (s *LogSuite) TestQuietAndVerbose(c *gc.C) {
157
157
        l := &cmd.Log{Verbose: true, Quiet: true}
158
 
        ctx := testing.Context(c)
 
158
        ctx := coretesting.Context(c)
159
159
        err := l.Start(ctx)
160
 
        c.Assert(err, gc.ErrorMatches, `"verbose" and "quiet" flags clash`)
 
160
        c.Assert(err, gc.ErrorMatches, `"verbose" and "quiet" flags clash, please use one or the other, not both`)
161
161
}
162
162
 
163
163
func (s *LogSuite) TestOutputDefault(c *gc.C) {
164
164
        l := &cmd.Log{}
165
 
        ctx := testing.Context(c)
 
165
        ctx := coretesting.Context(c)
166
166
        err := l.Start(ctx)
167
167
        c.Assert(err, gc.IsNil)
168
168
 
169
 
        cmd.Infof("Writing info output")
170
 
        cmd.Verbosef("Writing verbose output")
 
169
        ctx.Infof("Writing info output")
 
170
        ctx.Verbosef("Writing verbose output")
171
171
 
172
 
        c.Assert(testing.Stderr(ctx), gc.Equals, "Writing info output\n")
 
172
        c.Assert(coretesting.Stderr(ctx), gc.Equals, "Writing info output\n")
173
173
}
174
174
 
175
175
func (s *LogSuite) TestOutputVerbose(c *gc.C) {
176
176
        l := &cmd.Log{Verbose: true}
177
 
        ctx := testing.Context(c)
 
177
        ctx := coretesting.Context(c)
178
178
        err := l.Start(ctx)
179
179
        c.Assert(err, gc.IsNil)
180
180
 
181
 
        cmd.Infof("Writing info output")
182
 
        cmd.Verbosef("Writing verbose output")
 
181
        ctx.Infof("Writing info output")
 
182
        ctx.Verbosef("Writing verbose output")
183
183
 
184
 
        c.Assert(testing.Stderr(ctx), gc.Equals, "Writing info output\nWriting verbose output\n")
 
184
        c.Assert(coretesting.Stderr(ctx), gc.Equals, "Writing info output\nWriting verbose output\n")
185
185
}
186
186
 
187
187
func (s *LogSuite) TestOutputQuiet(c *gc.C) {
188
188
        l := &cmd.Log{Quiet: true}
189
 
        ctx := testing.Context(c)
 
189
        ctx := coretesting.Context(c)
190
190
        err := l.Start(ctx)
191
191
        c.Assert(err, gc.IsNil)
192
192
 
193
 
        cmd.Infof("Writing info output")
194
 
        cmd.Verbosef("Writing verbose output")
 
193
        ctx.Infof("Writing info output")
 
194
        ctx.Verbosef("Writing verbose output")
195
195
 
196
 
        c.Assert(testing.Stderr(ctx), gc.Equals, "")
 
196
        c.Assert(coretesting.Stderr(ctx), gc.Equals, "")
197
197
}
198
198
 
199
199
func (s *LogSuite) TestOutputQuietLogs(c *gc.C) {
200
200
        l := &cmd.Log{Quiet: true, Path: "foo.log", Config: "<root>=INFO"}
201
 
        ctx := testing.Context(c)
 
201
        ctx := coretesting.Context(c)
202
202
        err := l.Start(ctx)
203
203
        c.Assert(err, gc.IsNil)
204
204
 
205
 
        cmd.Infof("Writing info output")
206
 
        cmd.Verbosef("Writing verbose output")
 
205
        ctx.Infof("Writing info output")
 
206
        ctx.Verbosef("Writing verbose output")
207
207
 
208
208
        content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log"))
209
209
        c.Assert(err, gc.IsNil)
210
 
        c.Assert(testing.Stderr(ctx), gc.Equals, "")
 
210
        c.Assert(coretesting.Stderr(ctx), gc.Equals, "")
211
211
        c.Assert(string(content), gc.Matches, `^.*INFO .* Writing info output\n.*INFO .*Writing verbose output\n.*`)
212
212
}
213
213
 
214
214
func (s *LogSuite) TestOutputDefaultLogsVerbose(c *gc.C) {
215
215
        l := &cmd.Log{Path: "foo.log", Config: "<root>=INFO"}
216
 
        ctx := testing.Context(c)
 
216
        ctx := coretesting.Context(c)
217
217
        err := l.Start(ctx)
218
218
        c.Assert(err, gc.IsNil)
219
219
 
220
 
        cmd.Infof("Writing info output")
221
 
        cmd.Verbosef("Writing verbose output")
 
220
        ctx.Infof("Writing info output")
 
221
        ctx.Verbosef("Writing verbose output")
222
222
 
223
223
        content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log"))
224
224
        c.Assert(err, gc.IsNil)
225
 
        c.Assert(testing.Stderr(ctx), gc.Equals, "Writing info output\n")
 
225
        c.Assert(coretesting.Stderr(ctx), gc.Equals, "Writing info output\n")
226
226
        c.Assert(string(content), gc.Matches, `^.*INFO .*Writing verbose output\n.*`)
227
227
}