From 1247c789aa9ec3fdc518acd989f32cac76708de6 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 6 Feb 2019 09:03:49 -0500 Subject: [PATCH] lang: Remove unnecessary log package --- lang/funcs/facts/func_test.go | 33 ++++++++++----------------------- lang/interpolate_test.go | 6 +++--- lang/interpret_test.go | 16 ++++++++-------- lang/lang_test.go | 2 +- lang/unification_test.go | 2 +- puppet/puppet.go | 2 -- 6 files changed, 23 insertions(+), 38 deletions(-) diff --git a/lang/funcs/facts/func_test.go b/lang/funcs/facts/func_test.go index 934cf136..7a54b2aa 100644 --- a/lang/funcs/facts/func_test.go +++ b/lang/funcs/facts/func_test.go @@ -20,7 +20,6 @@ package facts import ( - "log" "testing" "time" @@ -28,70 +27,58 @@ import ( "github.com/purpleidea/mgmt/pgraph" ) -const Debug = false // switch on for more interactive log messages when testing! - -// logf switches messages to use realtime logging when debugging tests, and the -// quiet logging which is not shown until test failures, when debug mode is off. -func logf(t *testing.T, format string, args ...interface{}) { - if Debug { - log.Printf(format, args...) - } else { - t.Logf(format, args...) - } -} - func TestFuncGraph0(t *testing.T) { - logf(t, "Hello!") + t.Logf("Hello!") g, _ := pgraph.NewGraph("empty") // empty graph obj := &funcs.Engine{ Graph: g, } - logf(t, "Init...") + t.Logf("Init...") if err := obj.Init(); err != nil { t.Errorf("could not init: %+v", err) return } - logf(t, "Validate...") + t.Logf("Validate...") if err := obj.Validate(); err != nil { t.Errorf("could not validate: %+v", err) return } - logf(t, "Run...") + t.Logf("Run...") if err := obj.Run(); err != nil { t.Errorf("could not run: %+v", err) return } // wait for some activity - logf(t, "Stream...") + t.Logf("Stream...") stream := obj.Stream() - logf(t, "Loop...") + t.Logf("Loop...") br := time.After(time.Duration(5) * time.Second) Loop: for { select { case err, ok := <-stream: if !ok { - logf(t, "Stream break...") + t.Logf("Stream break...") break Loop } if err != nil { - logf(t, "Error: %+v", err) + t.Logf("Error: %+v", err) continue } case <-br: - logf(t, "Break...") + t.Logf("Break...") t.Errorf("empty graph should have closed stream") break Loop } } - logf(t, "Closing...") + t.Logf("Closing...") if err := obj.Close(); err != nil { t.Errorf("could not close: %+v", err) return diff --git a/lang/interpolate_test.go b/lang/interpolate_test.go index f519dfe1..24f7e81d 100644 --- a/lang/interpolate_test.go +++ b/lang/interpolate_test.go @@ -152,7 +152,7 @@ func TestInterpolate0(t *testing.T) { t.Logf("test #%d: AST: %+v", index, ast) data := &interfaces.Data{ - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { t.Logf("ast: "+format, v...) }, @@ -388,7 +388,7 @@ func TestInterpolateBasicStmt(t *testing.T) { ast, fail, exp := tc.ast, tc.fail, tc.exp data := &interfaces.Data{ - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { t.Logf("ast: "+format, v...) }, @@ -709,7 +709,7 @@ func TestInterpolateBasicExpr(t *testing.T) { ast, fail, exp := tc.ast, tc.fail, tc.exp data := &interfaces.Data{ - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { t.Logf("ast: "+format, v...) }, diff --git a/lang/interpret_test.go b/lang/interpret_test.go index 3f08c468..b5644d07 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -433,7 +433,7 @@ func TestAstFunc0(t *testing.T) { t.Logf("test #%d: AST: %+v", index, ast) data := &interfaces.Data{ - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { t.Logf("ast: "+format, v...) }, @@ -723,7 +723,7 @@ func TestAstFunc1(t *testing.T) { Metadata: output.Metadata, Modules: "/" + interfaces.ModuleDirectory, // not really needed here afaict - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { logf("ast: "+format, v...) }, @@ -1052,7 +1052,7 @@ func TestAstFunc2(t *testing.T) { Metadata: output.Metadata, Modules: "/" + interfaces.ModuleDirectory, // not really needed here afaict - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { logf("ast: "+format, v...) }, @@ -1152,10 +1152,10 @@ func TestAstFunc2(t *testing.T) { // run the function engine once to get some real output funcs := &funcs.Engine{ - Graph: graph, // not the same as the output graph! - Hostname: "", // NOTE: empty b/c not used - World: nil, // NOTE: nil b/c not used - Debug: false, // TODO: set true if needed + Graph: graph, // not the same as the output graph! + Hostname: "", // NOTE: empty b/c not used + World: nil, // NOTE: nil b/c not used + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { logf("funcs: "+format, v...) }, @@ -1452,7 +1452,7 @@ func TestAstInterpret0(t *testing.T) { t.Logf("test #%d: AST: %+v", index, ast) data := &interfaces.Data{ - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { t.Logf("ast: "+format, v...) }, diff --git a/lang/lang_test.go b/lang/lang_test.go index edc49be5..fe17c964 100644 --- a/lang/lang_test.go +++ b/lang/lang_test.go @@ -117,7 +117,7 @@ func runInterpret(t *testing.T, code string) (*pgraph.Graph, error) { lang := &Lang{ Fs: fs, Input: "/" + interfaces.MetadataFilename, // start path in fs - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: logf, } if err := lang.Init(); err != nil { diff --git a/lang/unification_test.go b/lang/unification_test.go index 875546fc..7e2ec383 100644 --- a/lang/unification_test.go +++ b/lang/unification_test.go @@ -778,7 +778,7 @@ func TestUnification1(t *testing.T) { t.Logf("\n\ntest #%d: AST (before): %+v\n", index, ast) data := &interfaces.Data{ - Debug: true, + Debug: testing.Verbose(), // set via the -test.v flag to `go test` Logf: func(format string, v ...interface{}) { t.Logf(fmt.Sprintf("test #%d", index)+": ast: "+format, v...) }, diff --git a/puppet/puppet.go b/puppet/puppet.go index ad98eac1..53413805 100644 --- a/puppet/puppet.go +++ b/puppet/puppet.go @@ -34,8 +34,6 @@ import ( const ( // PuppetYAMLBufferSize is the maximum buffer size for the yaml input data PuppetYAMLBufferSize = 65535 - // Debug is a local debug constant used in this module - Debug = false // FIXME: integrate with global debug flag ) func (obj *GAPI) runPuppetCommand(cmd *exec.Cmd) ([]byte, error) {