~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/github.com/andelf/go-curl/logging_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
package curl
 
3
 
 
4
import (
 
5
        "testing"
 
6
        "bytes"
 
7
        "log"
 
8
        "os"
 
9
        "fmt"
 
10
        "regexp"
 
11
)
 
12
 
 
13
func TestDefaultLogLevel(t *testing.T) {
 
14
    if log_level != _DEFAULT_LOG_LEVEL {t.Error("Test failed, expected DEFAULT_LOG_LEVEL level.")}
 
15
}
 
16
 
 
17
func TestSetLogLevel(t *testing.T) {
 
18
    SetLogLevel("DEBUG")
 
19
    defer SetLogLevel("DEFAULT_LOG_LEVEL")
 
20
    if log_level != _DEBUG {t.Error("Test failed, expected DEBUG level.")}
 
21
    SetLogLevel("INFO")
 
22
    if log_level != _INFO {t.Error("Test failed, expected INFO level.")}
 
23
    SetLogLevel("WARN")
 
24
    if log_level != _WARN {t.Error("Test failed, expected WARN level.")}
 
25
    SetLogLevel("ERROR")
 
26
    if log_level != _ERROR {t.Error("Test failed, expected ERROR level.")}
 
27
}
 
28
 
 
29
var (
 
30
    testFormat = "test format %s"
 
31
    testArgument = "test string 1"
 
32
    expectedRegexp = regexp.MustCompile(".*" + fmt.Sprintf(testFormat, testArgument) + "\n$")
 
33
)
 
34
 
 
35
 
 
36
func TestLogf(t *testing.T) {
 
37
    buf := new(bytes.Buffer)
 
38
    log.SetOutput(buf)
 
39
    defer log.SetOutput(os.Stderr)
 
40
    SetLogLevel("DEBUG")
 
41
    defer SetLogLevel("DEFAULT_LOG_LEVEL")
 
42
 
 
43
    logf(_DEBUG, testFormat, testArgument)
 
44
    line := buf.String()
 
45
    matched := expectedRegexp.MatchString(line)
 
46
    if !matched {
 
47
        t.Errorf("log output should match %q and is %q.", expectedRegexp, line)
 
48
    }
 
49
}
 
50
 
 
51
func TestLogfUsesLogLevel(t *testing.T) {
 
52
    buf := new(bytes.Buffer)
 
53
    log.SetOutput(buf)
 
54
    defer log.SetOutput(os.Stderr)
 
55
    SetLogLevel("WARN")
 
56
    defer SetLogLevel("DEFAULT_LOG_LEVEL")
 
57
 
 
58
    logf(_DEBUG, testFormat, testArgument)
 
59
    line := buf.String()
 
60
    expectedLine := ""
 
61
    if line != expectedLine {
 
62
        t.Errorf("log output should match %q and is %q.", expectedLine, line)
 
63
    }
 
64
}