2015-05-01 08:28:01 +02:00
|
|
|
// Copyright (c) 2013-2015 The btcsuite developers
|
2014-07-31 17:22:33 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
package txscript_test
|
2014-07-31 17:22:33 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
"github.com/btcsuite/btcd/txscript"
|
2014-07-31 17:22:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetLogWriter(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
w io.Writer
|
|
|
|
level string
|
|
|
|
expected error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil writer",
|
|
|
|
w: nil,
|
|
|
|
level: "trace",
|
|
|
|
expected: errors.New("nil writer"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid log level",
|
|
|
|
w: os.Stdout,
|
|
|
|
level: "wrong",
|
|
|
|
expected: errors.New("invalid log level"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "use off level",
|
|
|
|
w: os.Stdout,
|
|
|
|
level: "off",
|
2015-01-16 16:15:43 +01:00
|
|
|
expected: errors.New("min level can't be greater than max. Got min: 6, max: 5"),
|
2014-07-31 17:22:33 +02:00
|
|
|
},
|
2014-08-03 22:30:37 +02:00
|
|
|
{
|
|
|
|
name: "pass",
|
|
|
|
w: os.Stdout,
|
|
|
|
level: "debug",
|
|
|
|
expected: nil,
|
|
|
|
},
|
2014-07-31 17:22:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
2015-01-30 07:03:01 +01:00
|
|
|
err := txscript.SetLogWriter(test.w, test.level)
|
2014-08-03 22:30:37 +02:00
|
|
|
if err != nil {
|
|
|
|
if err.Error() != test.expected.Error() {
|
|
|
|
t.Errorf("SetLogWriter #%d (%s) wrong result\n"+
|
2015-01-16 16:15:43 +01:00
|
|
|
"got: %v\nwant: %v", i, test.name, err,
|
2014-08-03 22:30:37 +02:00
|
|
|
test.expected)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if test.expected != nil {
|
|
|
|
t.Errorf("SetLogWriter #%d (%s) wrong result\n"+
|
2015-01-16 16:15:43 +01:00
|
|
|
"got: %v\nwant: %v", i, test.name, err,
|
2014-08-03 22:30:37 +02:00
|
|
|
test.expected)
|
|
|
|
}
|
2014-07-31 17:22:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|