lang: Remove unnecessary log package
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
package facts
|
package facts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -28,70 +27,58 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/pgraph"
|
"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) {
|
func TestFuncGraph0(t *testing.T) {
|
||||||
logf(t, "Hello!")
|
t.Logf("Hello!")
|
||||||
g, _ := pgraph.NewGraph("empty") // empty graph
|
g, _ := pgraph.NewGraph("empty") // empty graph
|
||||||
|
|
||||||
obj := &funcs.Engine{
|
obj := &funcs.Engine{
|
||||||
Graph: g,
|
Graph: g,
|
||||||
}
|
}
|
||||||
|
|
||||||
logf(t, "Init...")
|
t.Logf("Init...")
|
||||||
if err := obj.Init(); err != nil {
|
if err := obj.Init(); err != nil {
|
||||||
t.Errorf("could not init: %+v", err)
|
t.Errorf("could not init: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logf(t, "Validate...")
|
t.Logf("Validate...")
|
||||||
if err := obj.Validate(); err != nil {
|
if err := obj.Validate(); err != nil {
|
||||||
t.Errorf("could not validate: %+v", err)
|
t.Errorf("could not validate: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logf(t, "Run...")
|
t.Logf("Run...")
|
||||||
if err := obj.Run(); err != nil {
|
if err := obj.Run(); err != nil {
|
||||||
t.Errorf("could not run: %+v", err)
|
t.Errorf("could not run: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for some activity
|
// wait for some activity
|
||||||
logf(t, "Stream...")
|
t.Logf("Stream...")
|
||||||
stream := obj.Stream()
|
stream := obj.Stream()
|
||||||
logf(t, "Loop...")
|
t.Logf("Loop...")
|
||||||
br := time.After(time.Duration(5) * time.Second)
|
br := time.After(time.Duration(5) * time.Second)
|
||||||
Loop:
|
Loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err, ok := <-stream:
|
case err, ok := <-stream:
|
||||||
if !ok {
|
if !ok {
|
||||||
logf(t, "Stream break...")
|
t.Logf("Stream break...")
|
||||||
break Loop
|
break Loop
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logf(t, "Error: %+v", err)
|
t.Logf("Error: %+v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-br:
|
case <-br:
|
||||||
logf(t, "Break...")
|
t.Logf("Break...")
|
||||||
t.Errorf("empty graph should have closed stream")
|
t.Errorf("empty graph should have closed stream")
|
||||||
break Loop
|
break Loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logf(t, "Closing...")
|
t.Logf("Closing...")
|
||||||
if err := obj.Close(); err != nil {
|
if err := obj.Close(); err != nil {
|
||||||
t.Errorf("could not close: %+v", err)
|
t.Errorf("could not close: %+v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ func TestInterpolate0(t *testing.T) {
|
|||||||
t.Logf("test #%d: AST: %+v", index, ast)
|
t.Logf("test #%d: AST: %+v", index, ast)
|
||||||
|
|
||||||
data := &interfaces.Data{
|
data := &interfaces.Data{
|
||||||
Debug: true,
|
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||||
Logf: func(format string, v ...interface{}) {
|
Logf: func(format string, v ...interface{}) {
|
||||||
t.Logf("ast: "+format, v...)
|
t.Logf("ast: "+format, v...)
|
||||||
},
|
},
|
||||||
@@ -388,7 +388,7 @@ func TestInterpolateBasicStmt(t *testing.T) {
|
|||||||
ast, fail, exp := tc.ast, tc.fail, tc.exp
|
ast, fail, exp := tc.ast, tc.fail, tc.exp
|
||||||
|
|
||||||
data := &interfaces.Data{
|
data := &interfaces.Data{
|
||||||
Debug: true,
|
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||||
Logf: func(format string, v ...interface{}) {
|
Logf: func(format string, v ...interface{}) {
|
||||||
t.Logf("ast: "+format, v...)
|
t.Logf("ast: "+format, v...)
|
||||||
},
|
},
|
||||||
@@ -709,7 +709,7 @@ func TestInterpolateBasicExpr(t *testing.T) {
|
|||||||
ast, fail, exp := tc.ast, tc.fail, tc.exp
|
ast, fail, exp := tc.ast, tc.fail, tc.exp
|
||||||
|
|
||||||
data := &interfaces.Data{
|
data := &interfaces.Data{
|
||||||
Debug: true,
|
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||||
Logf: func(format string, v ...interface{}) {
|
Logf: func(format string, v ...interface{}) {
|
||||||
t.Logf("ast: "+format, v...)
|
t.Logf("ast: "+format, v...)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
t.Logf("test #%d: AST: %+v", index, ast)
|
t.Logf("test #%d: AST: %+v", index, ast)
|
||||||
|
|
||||||
data := &interfaces.Data{
|
data := &interfaces.Data{
|
||||||
Debug: true,
|
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||||
Logf: func(format string, v ...interface{}) {
|
Logf: func(format string, v ...interface{}) {
|
||||||
t.Logf("ast: "+format, v...)
|
t.Logf("ast: "+format, v...)
|
||||||
},
|
},
|
||||||
@@ -723,7 +723,7 @@ func TestAstFunc1(t *testing.T) {
|
|||||||
Metadata: output.Metadata,
|
Metadata: output.Metadata,
|
||||||
Modules: "/" + interfaces.ModuleDirectory, // not really needed here afaict
|
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: func(format string, v ...interface{}) {
|
||||||
logf("ast: "+format, v...)
|
logf("ast: "+format, v...)
|
||||||
},
|
},
|
||||||
@@ -1052,7 +1052,7 @@ func TestAstFunc2(t *testing.T) {
|
|||||||
Metadata: output.Metadata,
|
Metadata: output.Metadata,
|
||||||
Modules: "/" + interfaces.ModuleDirectory, // not really needed here afaict
|
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: func(format string, v ...interface{}) {
|
||||||
logf("ast: "+format, v...)
|
logf("ast: "+format, v...)
|
||||||
},
|
},
|
||||||
@@ -1152,10 +1152,10 @@ func TestAstFunc2(t *testing.T) {
|
|||||||
|
|
||||||
// run the function engine once to get some real output
|
// run the function engine once to get some real output
|
||||||
funcs := &funcs.Engine{
|
funcs := &funcs.Engine{
|
||||||
Graph: graph, // not the same as the output graph!
|
Graph: graph, // not the same as the output graph!
|
||||||
Hostname: "", // NOTE: empty b/c not used
|
Hostname: "", // NOTE: empty b/c not used
|
||||||
World: nil, // NOTE: nil 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: func(format string, v ...interface{}) {
|
||||||
logf("funcs: "+format, v...)
|
logf("funcs: "+format, v...)
|
||||||
},
|
},
|
||||||
@@ -1452,7 +1452,7 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
t.Logf("test #%d: AST: %+v", index, ast)
|
t.Logf("test #%d: AST: %+v", index, ast)
|
||||||
|
|
||||||
data := &interfaces.Data{
|
data := &interfaces.Data{
|
||||||
Debug: true,
|
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||||
Logf: func(format string, v ...interface{}) {
|
Logf: func(format string, v ...interface{}) {
|
||||||
t.Logf("ast: "+format, v...)
|
t.Logf("ast: "+format, v...)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func runInterpret(t *testing.T, code string) (*pgraph.Graph, error) {
|
|||||||
lang := &Lang{
|
lang := &Lang{
|
||||||
Fs: fs,
|
Fs: fs,
|
||||||
Input: "/" + interfaces.MetadataFilename, // start path in fs
|
Input: "/" + interfaces.MetadataFilename, // start path in fs
|
||||||
Debug: true,
|
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||||
Logf: logf,
|
Logf: logf,
|
||||||
}
|
}
|
||||||
if err := lang.Init(); err != nil {
|
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)
|
t.Logf("\n\ntest #%d: AST (before): %+v\n", index, ast)
|
||||||
|
|
||||||
data := &interfaces.Data{
|
data := &interfaces.Data{
|
||||||
Debug: true,
|
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||||
Logf: func(format string, v ...interface{}) {
|
Logf: func(format string, v ...interface{}) {
|
||||||
t.Logf(fmt.Sprintf("test #%d", index)+": ast: "+format, v...)
|
t.Logf(fmt.Sprintf("test #%d", index)+": ast: "+format, v...)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
// PuppetYAMLBufferSize is the maximum buffer size for the yaml input data
|
// PuppetYAMLBufferSize is the maximum buffer size for the yaml input data
|
||||||
PuppetYAMLBufferSize = 65535
|
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) {
|
func (obj *GAPI) runPuppetCommand(cmd *exec.Cmd) ([]byte, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user