-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput_test.go
54 lines (42 loc) · 1.4 KB
/
output_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
54
package logri_test
import (
"io/ioutil"
"os"
"path/filepath"
. "github.com/zenoss/logri"
. "gopkg.in/check.v1"
)
var emptyOptions map[string]string
func (s *LogriSuite) TestStdGetOutputWriters(c *C) {
w, err := GetOutputWriter(StdoutOutput, emptyOptions)
c.Assert(err, IsNil)
c.Assert(w, Equals, os.Stdout)
w, err = GetOutputWriter(StderrOutput, emptyOptions)
c.Assert(err, IsNil)
c.Assert(w, Equals, os.Stderr)
}
func (s *LogriSuite) TestGetFileOutputWriters(c *C) {
dir := c.MkDir()
file1 := filepath.Join(dir, "file1")
file2 := filepath.Join(dir, "file2")
// Validate that failing to pass a file option is an error
w1, err := GetOutputWriter(FileOutput, emptyOptions)
c.Assert(err, Equals, ErrInvalidOutputOptions)
// Get a proper writer
w1, err = GetOutputWriter(FileOutput, map[string]string{"file": file1})
c.Assert(err, IsNil)
// Verify that we actually have a writer to the file we specified, and that
// it was properly created
data := []byte("these are some data")
w1.Write(data)
read, err := ioutil.ReadFile(file1)
c.Assert(err, IsNil)
c.Assert(string(data), Equals, string(read))
// Make sure that a different file gives a different writer
w2, err := GetOutputWriter(FileOutput, map[string]string{"file": file2})
data2 := []byte("it other data now")
w2.Write(data2)
read2, err := ioutil.ReadFile(file2)
c.Assert(err, IsNil)
c.Assert(string(data2), Equals, string(read2))
}