~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to log/log_test.go

  • Committer: Mathieu Lonjaret
  • Date: 2011-12-01 15:37:58 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: mathieu.lonjaret@gmail.com-20111201153758-0a0kkibpl6pge2ie
logger: use global vars, becomes a package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package log_test
 
2
 
 
3
import (
 
4
        "bytes"
 
5
        . "launchpad.net/gocheck"
 
6
        jujulog "launchpad.net/juju/go/log"
 
7
        "log"
 
8
        "testing"
 
9
)
 
10
 
 
11
const (
 
12
        logPrefix = "JUJU "
 
13
        dbgPrefix = "JUJU:DEBUG "
 
14
)
 
15
 
 
16
func Test(t *testing.T) {
 
17
        TestingT(t)
 
18
}
 
19
 
 
20
type suite struct{}
 
21
 
 
22
var _ = Suite(suite{})
 
23
 
 
24
type logTest struct {
 
25
        input string
 
26
        debug bool
 
27
}
 
28
 
 
29
var logTests = []struct {
 
30
        input string
 
31
        debug bool
 
32
}{
 
33
        {
 
34
                input: "Hello World",
 
35
                debug: false,
 
36
        },
 
37
        {
 
38
                input: "Hello World",
 
39
                debug: true,
 
40
        },
 
41
}
 
42
 
 
43
func (suite) TestLogger(c *C) {
 
44
        buf := &bytes.Buffer{}
 
45
        jujulog.GlobalLogger = log.New(buf, "", 0)
 
46
        for _, t := range logTests {
 
47
                jujulog.Debug = t.debug
 
48
                jujulog.Logf(t.input)
 
49
                c.Assert(buf.String(), Equals, logPrefix+t.input+"\n")
 
50
                buf.Reset()
 
51
                jujulog.Debugf(t.input)
 
52
                if t.debug {
 
53
                        c.Assert(buf.String(), Equals, dbgPrefix+t.input+"\n")
 
54
                } else {
 
55
                        c.Assert(buf.String(), Equals, "")
 
56
                }
 
57
                buf.Reset()
 
58
        }
 
59
}