1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-05 16:27:05 +00:00

Error strings should not be capitalized

Error strings should not be capitalized (ST1005) & remove the
redundancy from array, slice or map composite literals.
Signed-off-by: Feruzjon Muyassarov <feruzjon.muyassarov@intel.com>
This commit is contained in:
Feruzjon Muyassarov 2022-10-14 15:43:18 +03:00
parent 14ad323e11
commit e79f09deb2
3 changed files with 33 additions and 33 deletions

View file

@ -30,17 +30,17 @@ import (
) )
var matchOps = map[MatchOp]struct{}{ var matchOps = map[MatchOp]struct{}{
MatchAny: struct{}{}, MatchAny: {},
MatchIn: struct{}{}, MatchIn: {},
MatchNotIn: struct{}{}, MatchNotIn: {},
MatchInRegexp: struct{}{}, MatchInRegexp: {},
MatchExists: struct{}{}, MatchExists: {},
MatchDoesNotExist: struct{}{}, MatchDoesNotExist: {},
MatchGt: struct{}{}, MatchGt: {},
MatchLt: struct{}{}, MatchLt: {},
MatchGtLt: struct{}{}, MatchGtLt: {},
MatchIsTrue: struct{}{}, MatchIsTrue: {},
MatchIsFalse: struct{}{}, MatchIsFalse: {},
} }
type valueRegexpCache []*regexp.Regexp type valueRegexpCache []*regexp.Regexp
@ -80,44 +80,44 @@ func (m *MatchExpression) Validate() error {
switch m.Op { switch m.Op {
case MatchExists, MatchDoesNotExist, MatchIsTrue, MatchIsFalse, MatchAny: case MatchExists, MatchDoesNotExist, MatchIsTrue, MatchIsFalse, MatchAny:
if len(m.Value) != 0 { if len(m.Value) != 0 {
return fmt.Errorf("Value must be empty for Op %q (have %v)", m.Op, m.Value) return fmt.Errorf("value must be empty for Op %q (have %v)", m.Op, m.Value)
} }
case MatchGt, MatchLt: case MatchGt, MatchLt:
if len(m.Value) != 1 { if len(m.Value) != 1 {
return fmt.Errorf("Value must contain exactly one element for Op %q (have %v)", m.Op, m.Value) return fmt.Errorf("value must contain exactly one element for Op %q (have %v)", m.Op, m.Value)
} }
if _, err := strconv.Atoi(m.Value[0]); err != nil { if _, err := strconv.Atoi(m.Value[0]); err != nil {
return fmt.Errorf("Value must be an integer for Op %q (have %v)", m.Op, m.Value[0]) return fmt.Errorf("value must be an integer for Op %q (have %v)", m.Op, m.Value[0])
} }
case MatchGtLt: case MatchGtLt:
if len(m.Value) != 2 { if len(m.Value) != 2 {
return fmt.Errorf("Value must contain exactly two elements for Op %q (have %v)", m.Op, m.Value) return fmt.Errorf("value must contain exactly two elements for Op %q (have %v)", m.Op, m.Value)
} }
var err error var err error
v := make([]int, 2) v := make([]int, 2)
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
if v[i], err = strconv.Atoi(m.Value[i]); err != nil { if v[i], err = strconv.Atoi(m.Value[i]); err != nil {
return fmt.Errorf("Value must contain integers for Op %q (have %v)", m.Op, m.Value) return fmt.Errorf("value must contain integers for Op %q (have %v)", m.Op, m.Value)
} }
} }
if v[0] >= v[1] { if v[0] >= v[1] {
return fmt.Errorf("Value[0] must be less than Value[1] for Op %q (have %v)", m.Op, m.Value) return fmt.Errorf("value[0] must be less than Value[1] for Op %q (have %v)", m.Op, m.Value)
} }
case MatchInRegexp: case MatchInRegexp:
if len(m.Value) == 0 { if len(m.Value) == 0 {
return fmt.Errorf("Value must be non-empty for Op %q", m.Op) return fmt.Errorf("value must be non-empty for Op %q", m.Op)
} }
m.valueRe = make([]*regexp.Regexp, len(m.Value)) m.valueRe = make([]*regexp.Regexp, len(m.Value))
for i, v := range m.Value { for i, v := range m.Value {
re, err := regexp.Compile(v) re, err := regexp.Compile(v)
if err != nil { if err != nil {
return fmt.Errorf("Value must only contain valid regexps for Op %q (have %v)", m.Op, m.Value) return fmt.Errorf("value must only contain valid regexps for Op %q (have %v)", m.Op, m.Value)
} }
m.valueRe[i] = re m.valueRe[i] = re
} }
default: default:
if len(m.Value) == 0 { if len(m.Value) == 0 {
return fmt.Errorf("Value must be non-empty for Op %q", m.Op) return fmt.Errorf("value must be non-empty for Op %q", m.Op)
} }
} }
return nil return nil

View file

@ -175,7 +175,7 @@ func TestRule(t *testing.T) {
// Test MatchAny // Test MatchAny
r5.MatchAny = []MatchAnyElem{ r5.MatchAny = []MatchAnyElem{
MatchAnyElem{ {
MatchFeatures: FeatureMatcher{ MatchFeatures: FeatureMatcher{
FeatureMatcherTerm{ FeatureMatcherTerm{
Feature: "domain-1.kf-1", Feature: "domain-1.kf-1",
@ -209,18 +209,18 @@ func TestRule(t *testing.T) {
func TestTemplating(t *testing.T) { func TestTemplating(t *testing.T) {
f := map[string]*feature.DomainFeatures{ f := map[string]*feature.DomainFeatures{
"domain_1": &feature.DomainFeatures{ "domain_1": {
Flags: map[string]feature.FlagFeatureSet{ Flags: map[string]feature.FlagFeatureSet{
"kf_1": feature.FlagFeatureSet{ "kf_1": {
Elements: map[string]feature.Nil{ Elements: map[string]feature.Nil{
"key-a": feature.Nil{}, "key-a": {},
"key-b": feature.Nil{}, "key-b": {},
"key-c": feature.Nil{}, "key-c": {},
}, },
}, },
}, },
Attributes: map[string]feature.AttributeFeatureSet{ Attributes: map[string]feature.AttributeFeatureSet{
"vf_1": feature.AttributeFeatureSet{ "vf_1": {
Elements: map[string]string{ Elements: map[string]string{
"key-1": "val-1", "key-1": "val-1",
"keu-2": "val-2", "keu-2": "val-2",
@ -229,21 +229,21 @@ func TestTemplating(t *testing.T) {
}, },
}, },
Instances: map[string]feature.InstanceFeatureSet{ Instances: map[string]feature.InstanceFeatureSet{
"if_1": feature.InstanceFeatureSet{ "if_1": {
Elements: []feature.InstanceFeature{ Elements: []feature.InstanceFeature{
feature.InstanceFeature{ {
Attributes: map[string]string{ Attributes: map[string]string{
"attr-1": "1", "attr-1": "1",
"attr-2": "val-2", "attr-2": "val-2",
}, },
}, },
feature.InstanceFeature{ {
Attributes: map[string]string{ Attributes: map[string]string{
"attr-1": "10", "attr-1": "10",
"attr-2": "val-20", "attr-2": "val-20",
}, },
}, },
feature.InstanceFeature{ {
Attributes: map[string]string{ Attributes: map[string]string{
"attr-1": "100", "attr-1": "100",
"attr-2": "val-200", "attr-2": "val-200",

View file

@ -52,7 +52,7 @@ func GuaranteedSleeperPod(cpuLimit string) *v1.Pod {
Spec: v1.PodSpec{ Spec: v1.PodSpec{
RestartPolicy: v1.RestartPolicyNever, RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{ Containers: []v1.Container{
v1.Container{ {
Name: "sleeper-gu-cnt", Name: "sleeper-gu-cnt",
Image: PauseImage, Image: PauseImage,
Resources: v1.ResourceRequirements{ Resources: v1.ResourceRequirements{
@ -78,7 +78,7 @@ func BestEffortSleeperPod() *v1.Pod {
Spec: v1.PodSpec{ Spec: v1.PodSpec{
RestartPolicy: v1.RestartPolicyNever, RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{ Containers: []v1.Container{
v1.Container{ {
Name: "sleeper-be-cnt", Name: "sleeper-be-cnt",
Image: PauseImage, Image: PauseImage,
}, },