From bdc37d099a5c23bff519a5a7c2f1e7f7c82b5668 Mon Sep 17 00:00:00 2001 From: Gregor Noczinski Date: Wed, 15 Jan 2025 09:47:58 +0100 Subject: [PATCH] Adjust govet findings --- access/config_test.go | 7 ++++--- access/permission.go | 8 +++----- access/permission_test.go | 22 ++++++++++++---------- access/type.go | 6 ++---- access/type_test.go | 22 ++++++++++++---------- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/access/config_test.go b/access/config_test.go index 78ee8cd..04d2c04 100644 --- a/access/config_test.go +++ b/access/config_test.go @@ -1,9 +1,10 @@ package access import ( + . "gopkg.in/check.v1" + . "github.com/echocat/caretakerd/testing" "github.com/echocat/caretakerd/values" - . "gopkg.in/check.v1" ) type ConfigTest struct{} @@ -52,7 +53,7 @@ func (s *ConfigTest) TestValidateWrongType(c *C) { actual := Config{ Type: Type(66), } - c.Assert(actual.Validate(), ErrorMatches, "Illegal access type: 66") + c.Assert(actual.Validate(), ErrorMatches, "illegal access type: 66") actual.Type = Trusted c.Assert(actual.Validate(), IsNil) } @@ -62,7 +63,7 @@ func (s *ConfigTest) TestValidateWrongPermission(c *C) { Type: Trusted, Permission: Permission(66), } - c.Assert(actual.Validate(), ErrorMatches, "Illegal permission: 66") + c.Assert(actual.Validate(), ErrorMatches, "illegal permission: 66") actual.Permission = ReadOnly c.Assert(actual.Validate(), IsNil) } diff --git a/access/permission.go b/access/permission.go index fc25c60..1d2d3da 100644 --- a/access/permission.go +++ b/access/permission.go @@ -5,8 +5,6 @@ import ( "fmt" "strconv" "strings" - - "github.com/echocat/caretakerd/errors" ) // Permission represents the service's/node's permissions in caretakerd. @@ -53,7 +51,7 @@ func (instance Permission) CheckedString() (string, error) { case ReadWrite: return "readWrite", nil } - return "", errors.New("Illegal permission: %d", instance) + return "", fmt.Errorf("illegal permission: %d", instance) } // Set the given string to current object from a string. @@ -66,7 +64,7 @@ func (instance *Permission) Set(value string) error { return nil } } - return fmt.Errorf("illegal permission type: %v", value) + return fmt.Errorf("illegal permission: %v", value) } lowerValue := strings.ToLower(value) for _, candidate := range AllPermissions { @@ -75,7 +73,7 @@ func (instance *Permission) Set(value string) error { return nil } } - return fmt.Errorf("illegal permission type: %v", value) + return fmt.Errorf("illegal permission: %v", value) } // MarshalYAML is used until yaml marshalling. Do not call directly. diff --git a/access/permission_test.go b/access/permission_test.go index 5b93516..2601f5c 100644 --- a/access/permission_test.go +++ b/access/permission_test.go @@ -1,10 +1,12 @@ package access import ( + "reflect" + + . "gopkg.in/check.v1" + "github.com/echocat/caretakerd/errors" . "github.com/echocat/caretakerd/testing" - . "gopkg.in/check.v1" - "reflect" ) type PermissionTest struct{} @@ -22,7 +24,7 @@ func (s *PermissionTest) TestString(c *C) { func (s *PermissionTest) TestStringPanic(c *C) { c.Assert(func() { _ = Permission(-1).String() - }, ThrowsPanicThatMatches, "Illegal permission: -1") + }, ThrowsPanicThatMatches, "illegal permission: -1") } func (s *PermissionTest) TestCheckedString(c *C) { @@ -35,7 +37,7 @@ func (s *PermissionTest) TestCheckedString(c *C) { func (s *PermissionTest) TestCheckedStringErrors(c *C) { r, err := Permission(-1).CheckedString() - c.Assert(err, ErrorMatches, "Illegal permission: -1") + c.Assert(err, ErrorMatches, "illegal permission: -1") c.Assert(r, Equals, "") } @@ -47,10 +49,10 @@ func (s *PermissionTest) TestSet(c *C) { c.Assert(actual.Set("readWrite"), IsNil) c.Assert(actual, Equals, ReadWrite) - c.Assert(actual.Set("xxx"), ErrorMatches, "Illegal permission: xxx") + c.Assert(actual.Set("xxx"), ErrorMatches, "illegal permission: xxx") c.Assert(actual, Equals, ReadWrite) - c.Assert(actual.Set("666"), ErrorMatches, "Illegal permission: 666") + c.Assert(actual.Set("666"), ErrorMatches, "illegal permission: 666") c.Assert(actual, Equals, ReadWrite) } @@ -75,7 +77,7 @@ func (s *PermissionTest) TestUnmarshalYAMLWithProblems(c *C) { c.Assert(actual.UnmarshalYAML(func(v interface{}) error { reflect.ValueOf(v).Elem().Set(reflect.ValueOf("foobar")) return nil - }), ErrorMatches, "Illegal permission: foobar") + }), ErrorMatches, "illegal permission: foobar") c.Assert(actual, Equals, Permission(-1)) c.Assert(actual.UnmarshalYAML(func(v interface{}) error { @@ -94,7 +96,7 @@ func (s *PermissionTest) TestMarshalJSON(c *C) { func (s *PermissionTest) TestMarshalJSONWithProblems(c *C) { actual := Permission(-1) pb, err := actual.MarshalJSON() - c.Assert(err, ErrorMatches, "Illegal permission: -1") + c.Assert(err, ErrorMatches, "illegal permission: -1") c.Assert(string(pb), Equals, "") } @@ -106,7 +108,7 @@ func (s *PermissionTest) TestUnmarshalJSON(c *C) { func (s *PermissionTest) TestUnmarshalJSONWithProblems(c *C) { actual := ReadOnly - c.Assert(actual.UnmarshalJSON([]byte("\"foobar\"")), ErrorMatches, "Illegal permission: foobar") + c.Assert(actual.UnmarshalJSON([]byte("\"foobar\"")), ErrorMatches, "illegal permission: foobar") c.Assert(actual, Equals, ReadOnly) c.Assert(actual.UnmarshalJSON([]byte("0000")), ErrorMatches, "invalid character '0' after top-level value") @@ -115,5 +117,5 @@ func (s *PermissionTest) TestUnmarshalJSONWithProblems(c *C) { func (s *PermissionTest) TestValidate(c *C) { c.Assert(ReadOnly.Validate(), IsNil) - c.Assert(Permission(-1).Validate(), ErrorMatches, "Illegal permission: -1") + c.Assert(Permission(-1).Validate(), ErrorMatches, "illegal permission: -1") } diff --git a/access/type.go b/access/type.go index 30f3827..993f722 100644 --- a/access/type.go +++ b/access/type.go @@ -5,8 +5,6 @@ import ( "fmt" "strconv" "strings" - - "github.com/echocat/caretakerd/errors" ) // Type indicates the validation type for the access of a service/node to caretakerd. @@ -62,7 +60,7 @@ func (instance Type) CheckedString() (string, error) { case GenerateToFile: return "generateToFile", nil } - return "", errors.New("Illegal access type: %d", instance) + return "", fmt.Errorf("illegal access type: %d", instance) } // Set sets the given string to the current object from a string. @@ -84,7 +82,7 @@ func (instance *Type) Set(value string) error { return nil } } - return fmt.Errorf("illegal permission type: %v", value) + return fmt.Errorf("illegal access type: %v", value) } // MarshalYAML is used until yaml marshalling. Do not call this method directly. diff --git a/access/type_test.go b/access/type_test.go index a700d12..ec23181 100644 --- a/access/type_test.go +++ b/access/type_test.go @@ -1,10 +1,12 @@ package access import ( + "reflect" + + . "gopkg.in/check.v1" + "github.com/echocat/caretakerd/errors" . "github.com/echocat/caretakerd/testing" - . "gopkg.in/check.v1" - "reflect" ) type TypeTest struct{} @@ -23,7 +25,7 @@ func (s *TypeTest) TestString(c *C) { func (s *TypeTest) TestStringPanic(c *C) { c.Assert(func() { _ = Type(-1).String() - }, ThrowsPanicThatMatches, "Illegal access type: -1") + }, ThrowsPanicThatMatches, "illegal access type: -1") } func (s *TypeTest) TestCheckedString(c *C) { @@ -36,7 +38,7 @@ func (s *TypeTest) TestCheckedString(c *C) { func (s *TypeTest) TestCheckedStringErrors(c *C) { r, err := Type(-1).CheckedString() - c.Assert(err, ErrorMatches, "Illegal access type: -1") + c.Assert(err, ErrorMatches, "illegal access type: -1") c.Assert(r, Equals, "") } @@ -48,10 +50,10 @@ func (s *TypeTest) TestSet(c *C) { c.Assert(actual.Set("generateToEnvironment"), IsNil) c.Assert(actual, Equals, GenerateToEnvironment) - c.Assert(actual.Set("xxx"), ErrorMatches, "Illegal access type: xxx") + c.Assert(actual.Set("xxx"), ErrorMatches, "illegal access type: xxx") c.Assert(actual, Equals, GenerateToEnvironment) - c.Assert(actual.Set("666"), ErrorMatches, "Illegal access type: 666") + c.Assert(actual.Set("666"), ErrorMatches, "illegal access type: 666") c.Assert(actual, Equals, GenerateToEnvironment) } @@ -76,7 +78,7 @@ func (s *TypeTest) TestUnmarshalYAMLWithProblems(c *C) { c.Assert(actual.UnmarshalYAML(func(v interface{}) error { reflect.ValueOf(v).Elem().Set(reflect.ValueOf("foobar")) return nil - }), ErrorMatches, "Illegal access type: foobar") + }), ErrorMatches, "illegal access type: foobar") c.Assert(actual, Equals, Type(-1)) c.Assert(actual.UnmarshalYAML(func(v interface{}) error { @@ -95,7 +97,7 @@ func (s *TypeTest) TestMarshalJSON(c *C) { func (s *TypeTest) TestMarshalJSONWithProblems(c *C) { actual := Type(-1) pb, err := actual.MarshalJSON() - c.Assert(err, ErrorMatches, "Illegal access type: -1") + c.Assert(err, ErrorMatches, "illegal access type: -1") c.Assert(string(pb), Equals, "") } @@ -107,7 +109,7 @@ func (s *TypeTest) TestUnmarshalJSON(c *C) { func (s *TypeTest) TestUnmarshalJSONWithProblems(c *C) { actual := Trusted - c.Assert(actual.UnmarshalJSON([]byte("\"foobar\"")), ErrorMatches, "Illegal access type: foobar") + c.Assert(actual.UnmarshalJSON([]byte("\"foobar\"")), ErrorMatches, "illegal access type: foobar") c.Assert(actual, Equals, Trusted) c.Assert(actual.UnmarshalJSON([]byte("0000")), ErrorMatches, "invalid character '0' after top-level value") @@ -116,7 +118,7 @@ func (s *TypeTest) TestUnmarshalJSONWithProblems(c *C) { func (s *TypeTest) TestValidate(c *C) { c.Assert(Trusted.Validate(), IsNil) - c.Assert(Type(-1).Validate(), ErrorMatches, "Illegal access type: -1") + c.Assert(Type(-1).Validate(), ErrorMatches, "illegal access type: -1") } func (s *TypeTest) TestIsTakingFilename(c *C) {