test: Catch naked returns and check for canonically named imports
This catches scenarios where we forgot to prefix the error with return. One of our contributors occasionally made this typo, and since core go vet didn't (surprisingly) catch it, we should add a test! It also adds a simple check for import naming aliases. Expanding this test to add other cases and check for differently named values might make sense.
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/purpleidea/mgmt/engine/util"
|
||||
engineUtil "github.com/purpleidea/mgmt/engine/util"
|
||||
)
|
||||
|
||||
func TestStructTagToFieldName0(t *testing.T) {
|
||||
@@ -33,7 +33,7 @@ func TestStructTagToFieldName0(t *testing.T) {
|
||||
Delta int `lang:"surprise"`
|
||||
}
|
||||
|
||||
mapping, err := util.StructTagToFieldName(&TestStruct{})
|
||||
mapping, err := engineUtil.StructTagToFieldName(&TestStruct{})
|
||||
if err != nil {
|
||||
t.Errorf("failed: %+v", err)
|
||||
return
|
||||
@@ -62,7 +62,7 @@ func TestLowerStructFieldNameToFieldName0(t *testing.T) {
|
||||
Delta int
|
||||
}
|
||||
|
||||
mapping, err := util.LowerStructFieldNameToFieldName(&TestStruct{})
|
||||
mapping, err := engineUtil.LowerStructFieldNameToFieldName(&TestStruct{})
|
||||
if err != nil {
|
||||
t.Errorf("failed: %+v", err)
|
||||
return
|
||||
@@ -100,7 +100,7 @@ func TestLowerStructFieldNameToFieldName1(t *testing.T) {
|
||||
Delta int
|
||||
}
|
||||
|
||||
mapping, err := util.LowerStructFieldNameToFieldName(&TestStruct{})
|
||||
mapping, err := engineUtil.LowerStructFieldNameToFieldName(&TestStruct{})
|
||||
if err == nil {
|
||||
t.Errorf("expected failure, but passed with: %+v", mapping)
|
||||
return
|
||||
@@ -108,7 +108,7 @@ func TestLowerStructFieldNameToFieldName1(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLowerStructFieldNameToFieldName2(t *testing.T) {
|
||||
mapping, err := util.LowerStructFieldNameToFieldName(&TestRes{})
|
||||
mapping, err := engineUtil.LowerStructFieldNameToFieldName(&TestRes{})
|
||||
if err != nil {
|
||||
t.Errorf("failed: %+v", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user