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