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

« back to all changes in this revision

Viewing changes to juju/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 juju_test
2
 
 
3
 
import (
4
 
        "bytes"
5
 
        . "launchpad.net/gocheck"
6
 
        "launchpad.net/juju/go/juju"
7
 
        "log"
8
 
)
9
 
 
10
 
const (
11
 
        logPrefix = "JUJU "
12
 
        dbgPrefix = "JUJU:DEBUG "
13
 
)
14
 
 
15
 
type logTest struct {
16
 
        input string
17
 
        debug bool
18
 
}
19
 
 
20
 
var logTests = []struct {
21
 
        input string
22
 
        debug bool
23
 
}{
24
 
        {
25
 
                input: "Hello World",
26
 
                debug: false,
27
 
        },
28
 
        {
29
 
                input: "Hello World",
30
 
                debug: true,
31
 
        },
32
 
}
33
 
 
34
 
func (suite) TestLogger(c *C) {
35
 
        buf := &bytes.Buffer{}
36
 
        l := log.New(buf, "", 0)
37
 
        juju.SetLogger(l)
38
 
        for _, t := range logTests {
39
 
                juju.SetDebug(t.debug)
40
 
                juju.Logf(t.input)
41
 
                c.Assert(buf.String(), Equals, logPrefix+t.input+"\n")
42
 
                buf.Reset()
43
 
                juju.Debugf(t.input)
44
 
                if t.debug {
45
 
                        c.Assert(buf.String(), Equals, dbgPrefix+t.input+"\n")
46
 
                } else {
47
 
                        c.Assert(buf.String(), Equals, "")
48
 
                }
49
 
                buf.Reset()
50
 
        }
51
 
}