test: Fix broken gometalinter test

The test for gometalinter got silently broken in an earlier commit.
Look for the missing space that was added back in this commit to see
why! In any case, this now fixes some of the things that weren't
previously caught by this change.

If anyone knows how to run these sorts of tests properly so that entire
packages are tested and so that we can enable additional tests, please
let me know!

It's also unclear why goreportcard catches a few additional problems
which aren't found by running this ourselves.

See:
https://goreportcard.com/report/github.com/purpleidea/mgmt
for more information.
This commit is contained in:
James Shubin
2018-02-14 14:34:36 -05:00
parent b0a8f585c3
commit 714afe35a1
5 changed files with 22 additions and 25 deletions

View File

@@ -322,10 +322,7 @@ func (obj *File) Truncate(size int64) error {
obj.ModTime = time.Now() obj.ModTime = time.Now()
// this pushes the new data and metadata up to etcd // this pushes the new data and metadata up to etcd
if err := obj.Sync(); err != nil { return obj.Sync()
return err
}
return nil
} }
// Read reads up to len(b) bytes from the File. It returns the number of bytes // Read reads up to len(b) bytes from the File. It returns the number of bytes

View File

@@ -37,7 +37,7 @@ func init() {
funcs.Register("vumeter", func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name funcs.Register("vumeter", func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name
} }
// VUMeter is a gimmic function to display a vu meter from the microphone. // VUMeterFunc is a gimmic function to display a vu meter from the microphone.
type VUMeterFunc struct { type VUMeterFunc struct {
init *interfaces.Init init *interfaces.Init
last types.Value // last value received to use for diff last types.Value // last value received to use for diff

View File

@@ -55,6 +55,8 @@ type Info struct {
Err error // did this fact validate? Err error // did this fact validate?
} }
// Init is the structure of values and references which is passed into all
// facts on initialization.
type Init struct { type Init struct {
Hostname string // uuid for the host Hostname string // uuid for the host
//Noop bool //Noop bool

View File

@@ -85,7 +85,7 @@ func (obj *StmtBind) Unify() ([]interfaces.Invariant, error) {
// that fulfill the Stmt interface do not produces vertices, where as their // that fulfill the Stmt interface do not produces vertices, where as their
// children might. This particular bind statement adds its linked expression to // children might. This particular bind statement adds its linked expression to
// the graph. It is not logically done in the ExprVar since that could exist // the graph. It is not logically done in the ExprVar since that could exist
// mulitple times for the single binding operation done here. // multiple times for the single binding operation done here.
func (obj *StmtBind) Graph() (*pgraph.Graph, error) { func (obj *StmtBind) Graph() (*pgraph.Graph, error) {
return obj.Value.Graph() return obj.Value.Graph()
} }
@@ -134,7 +134,7 @@ func (obj *StmtRes) Interpolate() (interfaces.Stmt, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *StmtRes) SetScope(scope *interfaces.Scope) error { func (obj *StmtRes) SetScope(scope *interfaces.Scope) error {
if err := obj.Name.SetScope(scope); err != nil { if err := obj.Name.SetScope(scope); err != nil {
return err return err
@@ -419,7 +419,7 @@ func (obj *StmtEdge) Interpolate() (interfaces.Stmt, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *StmtEdge) SetScope(scope *interfaces.Scope) error { func (obj *StmtEdge) SetScope(scope *interfaces.Scope) error {
for _, x := range obj.EdgeHalfList { for _, x := range obj.EdgeHalfList {
if err := x.Name.SetScope(scope); err != nil { if err := x.Name.SetScope(scope); err != nil {
@@ -592,7 +592,7 @@ func (obj *StmtIf) Interpolate() (interfaces.Stmt, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *StmtIf) SetScope(scope *interfaces.Scope) error { func (obj *StmtIf) SetScope(scope *interfaces.Scope) error {
if err := obj.Condition.SetScope(scope); err != nil { if err := obj.Condition.SetScope(scope); err != nil {
return err return err
@@ -1280,7 +1280,7 @@ func (obj *ExprList) Interpolate() (interfaces.Expr, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *ExprList) SetScope(scope *interfaces.Scope) error { func (obj *ExprList) SetScope(scope *interfaces.Scope) error {
for _, x := range obj.Elements { for _, x := range obj.Elements {
if err := x.SetScope(scope); err != nil { if err := x.SetScope(scope); err != nil {
@@ -1533,7 +1533,7 @@ func (obj *ExprMap) Interpolate() (interfaces.Expr, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *ExprMap) SetScope(scope *interfaces.Scope) error { func (obj *ExprMap) SetScope(scope *interfaces.Scope) error {
for _, x := range obj.KVs { for _, x := range obj.KVs {
if err := x.Key.SetScope(scope); err != nil { if err := x.Key.SetScope(scope); err != nil {
@@ -1869,7 +1869,7 @@ func (obj *ExprStruct) Interpolate() (interfaces.Expr, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *ExprStruct) SetScope(scope *interfaces.Scope) error { func (obj *ExprStruct) SetScope(scope *interfaces.Scope) error {
for _, x := range obj.Fields { for _, x := range obj.Fields {
if err := x.Value.SetScope(scope); err != nil { if err := x.Value.SetScope(scope); err != nil {
@@ -2164,10 +2164,7 @@ func (obj *ExprFunc) Func() (interfaces.Func, error) {
// ever receive any incoming values (no incoming edges) so this should never be // ever receive any incoming values (no incoming edges) so this should never be
// called. It has been implemented for uniformity. // called. It has been implemented for uniformity.
func (obj *ExprFunc) SetValue(value types.Value) error { func (obj *ExprFunc) SetValue(value types.Value) error {
if err := obj.typ.Cmp(value.Type()); err != nil { return obj.typ.Cmp(value.Type())
return err
}
return nil
} }
// Value returns the value of this expression in our type system. This will // Value returns the value of this expression in our type system. This will
@@ -2283,7 +2280,7 @@ func (obj *ExprCall) Interpolate() (interfaces.Expr, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *ExprCall) SetScope(scope *interfaces.Scope) error { func (obj *ExprCall) SetScope(scope *interfaces.Scope) error {
for _, x := range obj.Args { for _, x := range obj.Args {
if err := x.SetScope(scope); err != nil { if err := x.SetScope(scope); err != nil {
@@ -2876,18 +2873,15 @@ func (obj *ExprIf) Interpolate() (interfaces.Expr, error) {
} }
// SetScope stores the scope for later use in this resource and it's children, // SetScope stores the scope for later use in this resource and it's children,
// which it propogates this downwards to. // which it propagates this downwards to.
func (obj *ExprIf) SetScope(scope *interfaces.Scope) error { func (obj *ExprIf) SetScope(scope *interfaces.Scope) error {
if err := obj.Condition.SetScope(scope); err != nil {
return err
}
if err := obj.ThenBranch.SetScope(scope); err != nil { if err := obj.ThenBranch.SetScope(scope); err != nil {
return err return err
} }
if err := obj.ElseBranch.SetScope(scope); err != nil { if err := obj.ElseBranch.SetScope(scope); err != nil {
return err return err
} }
return nil return obj.Condition.SetScope(scope)
} }
// SetType is used to set the type of this expression once it is known. This // SetType is used to set the type of this expression once it is known. This

View File

@@ -27,7 +27,7 @@ gml='gometalinter --disable-all'
gml="$gml --enable=goimports" gml="$gml --enable=goimports"
gml="$gml --enable=golint" gml="$gml --enable=golint"
#gml="$gml --enable=gosimple" # TODO: only a few fixes needed #gml="$gml --enable=gosimple" # TODO: only a few fixes needed
gml="$gml --enable=gotype" #gml="$gml --enable=gotype"
#gml="$gml --enable=ineffassign" # TODO: only a few fixes needed #gml="$gml --enable=ineffassign" # TODO: only a few fixes needed
#gml="$gml --enable=interfacer" # TODO: only a few fixes needed #gml="$gml --enable=interfacer" # TODO: only a few fixes needed
#gml="$gml --enable=lll --line-length=200" # TODO: only a few fixes needed #gml="$gml --enable=lll --line-length=200" # TODO: only a few fixes needed
@@ -35,15 +35,18 @@ gml="$gml --enable=misspell"
#gml="$gml --enable=safesql" # FIXME: made my machine slow #gml="$gml --enable=safesql" # FIXME: made my machine slow
#gml="$gml --enable=staticcheck" # TODO: only a few fixes needed #gml="$gml --enable=staticcheck" # TODO: only a few fixes needed
#gml="$gml --enable=structcheck" # TODO: only a few fixes needed #gml="$gml --enable=structcheck" # TODO: only a few fixes needed
gml="$gml --enable=unconvert" #gml="$gml --enable=unconvert"
#gml="$gml --enable=unparam" # TODO: only a few fixes needed #gml="$gml --enable=unparam" # TODO: only a few fixes needed
#gml="$gml --enable=unused" # TODO: only a few fixes needed #gml="$gml --enable=unused" # TODO: only a few fixes needed
#gml="$gml --enable=varcheck" # TODO: only a few fixes needed #gml="$gml --enable=varcheck" # TODO: only a few fixes needed
gometalinter="$gml" gometalinter="$gml"
echo "Using: $gometalinter"
# loop through directories in an attempt to scan each go package # loop through directories in an attempt to scan each go package
# TODO: lint the *.go examples as individual files and not as a single *.go # TODO: lint the *.go examples as individual files and not as a single *.go
for dir in `find . -maxdepth 5 -type d -not -path './old/*' -not -path './old' -not -path './tmp/*' -not -path './tmp' -not -path './.*' -not -path './vendor/*' -not -path './bindata/*'-not -path ' ./examples/*' -not -path './test/*'`; do for dir in `find . -maxdepth 5 -type d -not -path './old/*' -not -path './old' -not -path './tmp/*' -not -path './tmp' -not -path './.*' -not -path './vendor/*' -not -path './bindata/*' -not -path ' ./examples/*' -not -path './test/*'`; do
#echo "Running in: $dir"
match="$dir/*.go" match="$dir/*.go"
#echo "match is: $match" #echo "match is: $match"
if ! ls $match &>/dev/null; then if ! ls $match &>/dev/null; then
@@ -51,6 +54,7 @@ for dir in `find . -maxdepth 5 -type d -not -path './old/*' -not -path './old' -
continue # no *.go files found continue # no *.go files found
fi fi
#echo "Running: $gometalinter '$dir'"
run-test $gometalinter "$dir" || fail_test "gometalinter did not pass" run-test $gometalinter "$dir" || fail_test "gometalinter did not pass"
done done