From 24c3873956a591f99c70973b3771cf0e75d97874 Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Thu, 31 Jul 2014 18:22:33 +0300 Subject: [PATCH] Add log testing 8/10 of SetLogWriter tested --- log_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ test_coverage.txt | 4 ++-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 log_test.go diff --git a/log_test.go b/log_test.go new file mode 100644 index 00000000..0a7527c6 --- /dev/null +++ b/log_test.go @@ -0,0 +1,51 @@ +// Copyright (c) 2013-2014 Conformal Systems LLC. +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +package btcscript_test + +import ( + "errors" + "io" + "os" + "testing" + + "github.com/conformal/btcscript" +) + +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", + expected: errors.New("Min level can't be greater than max. Got min: 6, max: 5"), + }, + } + + t.Logf("Running %d tests", len(tests)) + for i, test := range tests { + if err := btcscript.SetLogWriter(test.w, test.level); err.Error() != test.expected.Error() { + t.Errorf("SetLogWriter #%d (%s) wrong result\n"+ + "got: %x\nwant: %x", i, test.name, err, + test.expected) + } + } +} diff --git a/test_coverage.txt b/test_coverage.txt index d9638982..d34a6428 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -169,7 +169,7 @@ github.com/conformal/btcscript/script.go IsPushOnlyScript 75.00% (3/4) github.com/conformal/btcscript/script.go p2pkSignatureScript 75.00% (3/4) github.com/conformal/btcscript/script.go HasCanonicalPushes 71.43% (5/7) github.com/conformal/btcscript/script.go sign 69.23% (18/26) -github.com/conformal/btcscript/log.go SetLogWriter 0.00% (0/10) +github.com/conformal/btcscript/log.go SetLogWriter 0.00% (8/10) github.com/conformal/btcscript/script.go CalcMultiSigStats 0.00% (0/8) github.com/conformal/btcscript/script.go @586:34 0.00% (0/6) github.com/conformal/btcscript/script.go @574:34 0.00% (0/4) @@ -178,5 +178,5 @@ github.com/conformal/btcscript/log.go UseLogger 0.00% (0/1) github.com/conformal/btcscript/opcode.go opcodeDisabled 0.00% (0/1) github.com/conformal/btcscript/log.go logClosure.String 0.00% (0/1) github.com/conformal/btcscript/opcode.go @1803:33 0.00% (0/1) -github.com/conformal/btcscript -------------------------- 95.15% (1197/1258) +github.com/conformal/btcscript -------------------------- 95.79% (1205/1258)