forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger_test.go
51 lines (40 loc) · 1.44 KB
/
logger_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
package qb
import (
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
// func TestLogger(t *testing.T) {
// // engine, err := New("default", ":memory:")
// // metadata := MetaData()
// // actors := Table("actors",
// // Column("id", BigInt()).NotNull(),
// // PrimaryKey("id"),
// // )
// // metadata.AddTable(actors)
// // metadata.CreateAll(engine)
// defer metadata.DropAll(engine)
// logCapture := &TestingLogWriter{t, nil}
// defer logCapture.Flush()
// engine.SetLogger(&DefaultLogger{LQuery | LBindings, log.New(logCapture, "", log.LstdFlags)})
// engine.Logger().SetLogFlags(LQuery)
// _, err = engine.Exec(actors.Insert().Values(map[string]interface{}{"id": 5}))
// assert.Nil(t, err)
// engine.Logger().SetLogFlags(LQuery | LBindings)
// _, err = engine.Exec(actors.Insert().Values(map[string]interface{}{"id": 10}))
// assert.Nil(t, err)
// assert.Equal(t, engine.Logger().LogFlags(), LQuery|LBindings)
// }
func TestLoggerFlags(t *testing.T) {
logger := DefaultLogger{LDefault, log.New(os.Stdout, "", -1)}
logger.SetLogFlags(LBindings)
assert.Equal(t, logger.LogFlags(), LBindings)
// engine, err := New("sqlite3", ":memory:")
// assert.Equal(t, nil, err)
// before setting flags, this is on the default
// assert.Equal(t, engine.Logger().LogFlags(), LDefault)
// engine.SetLogFlags(LBindings)
// after setting flags, we have the expected value
// assert.Equal(t, engine.Logger().LogFlags(), LBindings)
}