Skip to content

Commit

Permalink
Adjust govet findings
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Jan 15, 2025
1 parent ef2893a commit bdc37d0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
7 changes: 4 additions & 3 deletions access/config_test.go
Original file line number Diff line number Diff line change
@@ -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{}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
8 changes: 3 additions & 5 deletions access/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"strconv"
"strings"

"github.com/echocat/caretakerd/errors"
)

// Permission represents the service's/node's permissions in caretakerd.
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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.
Expand Down
22 changes: 12 additions & 10 deletions access/permission_test.go
Original file line number Diff line number Diff line change
@@ -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{}
Expand All @@ -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) {
Expand All @@ -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, "")
}

Expand All @@ -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)
}

Expand All @@ -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 {
Expand All @@ -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, "")
}

Expand All @@ -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")
Expand All @@ -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")
}
6 changes: 2 additions & 4 deletions access/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
22 changes: 12 additions & 10 deletions access/type_test.go
Original file line number Diff line number Diff line change
@@ -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{}
Expand All @@ -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) {
Expand All @@ -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, "")
}

Expand All @@ -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)
}

Expand All @@ -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 {
Expand All @@ -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, "")
}

Expand All @@ -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")
Expand All @@ -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) {
Expand Down

0 comments on commit bdc37d0

Please sign in to comment.