Skip to content

Commit

Permalink
Merge pull request #921 from fmuyassarov/cleanup
Browse files Browse the repository at this point in the history
Error strings should not be capitalized
  • Loading branch information
k8s-ci-robot authored Oct 14, 2022
2 parents 14ad323 + e79f09d commit 3b4f55b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
40 changes: 20 additions & 20 deletions pkg/apis/nfd/v1alpha1/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ import (
)

var matchOps = map[MatchOp]struct{}{
MatchAny: struct{}{},
MatchIn: struct{}{},
MatchNotIn: struct{}{},
MatchInRegexp: struct{}{},
MatchExists: struct{}{},
MatchDoesNotExist: struct{}{},
MatchGt: struct{}{},
MatchLt: struct{}{},
MatchGtLt: struct{}{},
MatchIsTrue: struct{}{},
MatchIsFalse: struct{}{},
MatchAny: {},
MatchIn: {},
MatchNotIn: {},
MatchInRegexp: {},
MatchExists: {},
MatchDoesNotExist: {},
MatchGt: {},
MatchLt: {},
MatchGtLt: {},
MatchIsTrue: {},
MatchIsFalse: {},
}

type valueRegexpCache []*regexp.Regexp
Expand Down Expand Up @@ -80,44 +80,44 @@ func (m *MatchExpression) Validate() error {
switch m.Op {
case MatchExists, MatchDoesNotExist, MatchIsTrue, MatchIsFalse, MatchAny:
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:
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 {
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:
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
v := make([]int, 2)
for i := 0; i < 2; i++ {
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] {
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:
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))
for i, v := range m.Value {
re, err := regexp.Compile(v)
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
}
default:
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
Expand Down
22 changes: 11 additions & 11 deletions pkg/apis/nfd/v1alpha1/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestRule(t *testing.T) {

// Test MatchAny
r5.MatchAny = []MatchAnyElem{
MatchAnyElem{
{
MatchFeatures: FeatureMatcher{
FeatureMatcherTerm{
Feature: "domain-1.kf-1",
Expand Down Expand Up @@ -209,18 +209,18 @@ func TestRule(t *testing.T) {

func TestTemplating(t *testing.T) {
f := map[string]*feature.DomainFeatures{
"domain_1": &feature.DomainFeatures{
"domain_1": {
Flags: map[string]feature.FlagFeatureSet{
"kf_1": feature.FlagFeatureSet{
"kf_1": {
Elements: map[string]feature.Nil{
"key-a": feature.Nil{},
"key-b": feature.Nil{},
"key-c": feature.Nil{},
"key-a": {},
"key-b": {},
"key-c": {},
},
},
},
Attributes: map[string]feature.AttributeFeatureSet{
"vf_1": feature.AttributeFeatureSet{
"vf_1": {
Elements: map[string]string{
"key-1": "val-1",
"keu-2": "val-2",
Expand All @@ -229,21 +229,21 @@ func TestTemplating(t *testing.T) {
},
},
Instances: map[string]feature.InstanceFeatureSet{
"if_1": feature.InstanceFeatureSet{
"if_1": {
Elements: []feature.InstanceFeature{
feature.InstanceFeature{
{
Attributes: map[string]string{
"attr-1": "1",
"attr-2": "val-2",
},
},
feature.InstanceFeature{
{
Attributes: map[string]string{
"attr-1": "10",
"attr-2": "val-20",
},
},
feature.InstanceFeature{
{
Attributes: map[string]string{
"attr-1": "100",
"attr-2": "val-200",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GuaranteedSleeperPod(cpuLimit string) *v1.Pod {
Spec: v1.PodSpec{
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
v1.Container{
{
Name: "sleeper-gu-cnt",
Image: PauseImage,
Resources: v1.ResourceRequirements{
Expand All @@ -78,7 +78,7 @@ func BestEffortSleeperPod() *v1.Pod {
Spec: v1.PodSpec{
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
v1.Container{
{
Name: "sleeper-be-cnt",
Image: PauseImage,
},
Expand Down

0 comments on commit 3b4f55b

Please sign in to comment.