Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
0fe29232
Commit
0fe29232
authored
Nov 05, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove obsolete ErrorList Prefix logic
parent
e6df0b1a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 addition
and
83 deletions
+1
-83
validation.go
pkg/apis/extensions/validation/validation.go
+1
-1
errors.go
pkg/util/validation/errors.go
+0
-22
errors_test.go
pkg/util/validation/errors_test.go
+0
-60
No files found.
pkg/apis/extensions/validation/validation.go
View file @
0fe29232
...
...
@@ -53,7 +53,7 @@ func validateHorizontalPodAutoscalerSpec(autoscaler extensions.HorizontalPodAuto
allErrs
=
append
(
allErrs
,
validation
.
NewInvalidError
(
fldPath
.
Child
(
"cpuUtilization"
,
"targetPercentage"
),
autoscaler
.
CPUUtilization
.
TargetPercentage
,
`must be greater than or equal to 1`
))
}
if
refErrs
:=
ValidateSubresourceReference
(
autoscaler
.
ScaleRef
,
fldPath
.
Child
(
"scaleRef"
));
len
(
refErrs
)
>
0
{
allErrs
=
append
(
allErrs
,
refErrs
.
Prefix
(
"scaleRef"
)
.
..
)
allErrs
=
append
(
allErrs
,
refErrs
...
)
}
else
if
autoscaler
.
ScaleRef
.
Subresource
!=
"scale"
{
allErrs
=
append
(
allErrs
,
validation
.
NewNotSupportedError
(
fldPath
.
Child
(
"scaleRef"
,
"subresource"
),
autoscaler
.
ScaleRef
.
Subresource
,
[]
string
{
"scale"
}))
}
...
...
pkg/util/validation/errors.go
View file @
0fe29232
...
...
@@ -181,28 +181,6 @@ func NewInternalError(field *FieldPath, err error) *Error {
// ErrorList holds a set of errors.
type
ErrorList
[]
*
Error
// Prefix adds a prefix to the Field of every Error in the list.
// Returns the list for convenience.
func
(
list
ErrorList
)
Prefix
(
prefix
string
)
ErrorList
{
for
i
:=
range
list
{
err
:=
list
[
i
]
if
strings
.
HasPrefix
(
err
.
Field
,
"["
)
{
err
.
Field
=
prefix
+
err
.
Field
}
else
if
len
(
err
.
Field
)
!=
0
{
err
.
Field
=
prefix
+
"."
+
err
.
Field
}
else
{
err
.
Field
=
prefix
}
}
return
list
}
// PrefixIndex adds an index to the Field of every Error in the list.
// Returns the list for convenience.
func
(
list
ErrorList
)
PrefixIndex
(
index
int
)
ErrorList
{
return
list
.
Prefix
(
fmt
.
Sprintf
(
"[%d]"
,
index
))
}
// NewErrorTypeMatcher returns an errors.Matcher that returns true
// if the provided error is a Error and has the provided ErrorType.
func
NewErrorTypeMatcher
(
t
ErrorType
)
utilerrors
.
Matcher
{
...
...
pkg/util/validation/errors_test.go
View file @
0fe29232
...
...
@@ -132,63 +132,3 @@ func TestErrListFilter(t *testing.T) {
t
.
Errorf
(
"should filter"
)
}
}
func
TestErrListPrefix
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
Err
*
Error
Expected
string
}{
{
NewNotFoundError
(
"[0].bar"
,
"value"
),
"foo[0].bar"
,
},
{
NewInvalidError
(
"field"
,
"value"
,
""
),
"foo.field"
,
},
{
NewDuplicateError
(
""
,
"value"
),
"foo"
,
},
}
for
_
,
testCase
:=
range
testCases
{
errList
:=
ErrorList
{
testCase
.
Err
}
prefix
:=
errList
.
Prefix
(
"foo"
)
if
prefix
==
nil
||
len
(
prefix
)
!=
len
(
errList
)
{
t
.
Errorf
(
"Prefix should return self"
)
}
if
e
,
a
:=
testCase
.
Expected
,
errList
[
0
]
.
Field
;
e
!=
a
{
t
.
Errorf
(
"expected %s, got %s"
,
e
,
a
)
}
}
}
func
TestErrListPrefixIndex
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
Err
*
Error
Expected
string
}{
{
NewNotFoundError
(
"[0].bar"
,
"value"
),
"[1][0].bar"
,
},
{
NewInvalidError
(
"field"
,
"value"
,
""
),
"[1].field"
,
},
{
NewDuplicateError
(
""
,
"value"
),
"[1]"
,
},
}
for
_
,
testCase
:=
range
testCases
{
errList
:=
ErrorList
{
testCase
.
Err
}
prefix
:=
errList
.
PrefixIndex
(
1
)
if
prefix
==
nil
||
len
(
prefix
)
!=
len
(
errList
)
{
t
.
Errorf
(
"PrefixIndex should return self"
)
}
if
e
,
a
:=
testCase
.
Expected
,
errList
[
0
]
.
Field
;
e
!=
a
{
t
.
Errorf
(
"expected %s, got %s"
,
e
,
a
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment