github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/database/log_test.go (about) 1 // Copyright (c) 2015-2016 The btcsuite developers 2 // Copyright (c) 2016 The Dash developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package database_test 7 8 import ( 9 "errors" 10 "io" 11 "os" 12 "testing" 13 14 "github.com/BlockABC/godash/database" 15 ) 16 17 // TestSetLogWriter ensures the 18 func TestSetLogWriter(t *testing.T) { 19 tests := []struct { 20 name string 21 w io.Writer 22 level string 23 expected error 24 }{ 25 { 26 name: "nil writer", 27 w: nil, 28 level: "trace", 29 expected: errors.New("nil writer"), 30 }, 31 { 32 name: "invalid log level", 33 w: os.Stdout, 34 level: "wrong", 35 expected: errors.New("invalid log level"), 36 }, 37 { 38 name: "use off level", 39 w: os.Stdout, 40 level: "off", 41 expected: errors.New("min level can't be greater than max. Got min: 6, max: 5"), 42 }, 43 { 44 name: "pass", 45 w: os.Stdout, 46 level: "debug", 47 expected: nil, 48 }, 49 } 50 51 t.Logf("Running %d tests", len(tests)) 52 for i, test := range tests { 53 err := database.SetLogWriter(test.w, test.level) 54 if err != nil { 55 if err.Error() != test.expected.Error() { 56 t.Errorf("SetLogWriter #%d (%s) wrong result\n"+ 57 "got: %v\nwant: %v", i, test.name, err, 58 test.expected) 59 } 60 } else { 61 if test.expected != nil { 62 t.Errorf("SetLogWriter #%d (%s) wrong result\n"+ 63 "got: %v\nwant: %v", i, test.name, err, 64 test.expected) 65 } 66 } 67 } 68 }