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