lang: Remove unnecessary log package
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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...)
|
||||
},
|
||||
|
||||
@@ -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...)
|
||||
},
|
||||
@@ -1155,7 +1155,7 @@ func TestAstFunc2(t *testing.T) {
|
||||
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
|
||||
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...)
|
||||
},
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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...)
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user