-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlog_test.go
53 lines (42 loc) · 1.07 KB
/
log_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package go_bagit_test
import (
"bytes"
stdlog "log"
"testing"
go_bagit "github.com/nyudlts/go-bagit"
)
func TestWithLogger(t *testing.T) {
t.Run("It panics when a nil value is passed", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Fatal("WithLogger did not panic")
}
}()
go_bagit.WithLogger(nil)
})
t.Run("It replaces the library logger", func(t *testing.T) {
var buf bytes.Buffer
tlog := stdlog.New(&buf, "", stdlog.LstdFlags)
go_bagit.WithLogger(tlog)
_, err := go_bagit.GetExistingBag("/dev/null")
if err == nil {
t.Error(err)
}
/*
_ = b.ValidateBag(false, false)
want := []byte("ERROR - open /dev/null/bag-info.txt: not a directory")
if !bytes.Contains(buf.Bytes(), want) {
t.Fatal("WithLogger did not replace the library logger")
}
*/
})
}
func TestLogger(t *testing.T) {
t.Run("It returns the current logger", func(t *testing.T) {
go_bagit.WithLogger(stdlog.Default())
logger := go_bagit.Logger()
if logger != stdlog.Default() {
t.Fatal("Logger returned an expected value")
}
})
}