-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappender_test.go
More file actions
49 lines (44 loc) · 1.05 KB
/
appender_test.go
File metadata and controls
49 lines (44 loc) · 1.05 KB
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
package loggo
import (
"bytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io"
"io/ioutil"
"os"
"text/template"
)
var _ = Describe("Appender", func() {
Describe("writerAppender", func() {
content := "foo"
tpl, _ := template.New("foo").Parse("{{.Content}}")
msg := &Message{
Level: Debug,
Content: content,
tpl: tpl,
}
It("should write to Writer", func() {
w := bytes.NewBufferString("")
appender := NewWriterAppender(w)
appender.Append(msg)
Expect(w.String()).To(Equal("foo"))
})
It("should write files", func() {
path := "/tmp/foo.log"
f, err := os.Create(path)
Expect(err).To(BeNil())
content, err := ioutil.ReadAll(f)
Expect(err).To(BeNil())
Expect(content).To(BeEmpty())
f.Close()
appender, err := NewFileAppender(path)
Expect(err).To(BeNil())
appender.Append(msg)
Expect(appender.(io.Closer).Close()).To(BeNil())
content, err = ioutil.ReadFile(path)
Expect(err).To(BeNil())
Expect(string(content)).To(Equal("foo"))
Expect(os.Remove(path)).To(BeNil())
})
})
})