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
536313c8
Commit
536313c8
authored
Aug 06, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9472 from deads2k/expose-name-validation
expose common name validation methods
parents
2abf5dfb
d73faa82
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
37 deletions
+37
-37
validation.go
pkg/api/validation/validation.go
+28
-28
validation_test.go
pkg/api/validation/validation_test.go
+9
-9
No files found.
pkg/api/validation/validation.go
View file @
536313c8
This diff is collapsed.
Click to expand it.
pkg/api/validation/validation_test.go
View file @
536313c8
...
@@ -107,7 +107,7 @@ func TestValidateObjectMetaUpdateIgnoresCreationTimestamp(t *testing.T) {
...
@@ -107,7 +107,7 @@ func TestValidateObjectMetaUpdateIgnoresCreationTimestamp(t *testing.T) {
// Ensure trailing slash is allowed in generate name
// Ensure trailing slash is allowed in generate name
func
TestValidateObjectMetaTrimsTrailingSlash
(
t
*
testing
.
T
)
{
func
TestValidateObjectMetaTrimsTrailingSlash
(
t
*
testing
.
T
)
{
errs
:=
ValidateObjectMeta
(
&
api
.
ObjectMeta
{
Name
:
"test"
,
GenerateName
:
"foo-"
},
false
,
n
ameIsDNSSubdomain
)
errs
:=
ValidateObjectMeta
(
&
api
.
ObjectMeta
{
Name
:
"test"
,
GenerateName
:
"foo-"
},
false
,
N
ameIsDNSSubdomain
)
if
len
(
errs
)
!=
0
{
if
len
(
errs
)
!=
0
{
t
.
Fatalf
(
"unexpected errors: %v"
,
errs
)
t
.
Fatalf
(
"unexpected errors: %v"
,
errs
)
}
}
...
@@ -504,8 +504,8 @@ func TestValidateVolumes(t *testing.T) {
...
@@ -504,8 +504,8 @@ func TestValidateVolumes(t *testing.T) {
t
.
Errorf
(
"%s: expected errors to have field %s: %v"
,
k
,
v
.
F
,
errs
[
i
])
t
.
Errorf
(
"%s: expected errors to have field %s: %v"
,
k
,
v
.
F
,
errs
[
i
])
}
}
detail
:=
errs
[
i
]
.
(
*
errors
.
ValidationError
)
.
Detail
detail
:=
errs
[
i
]
.
(
*
errors
.
ValidationError
)
.
Detail
if
detail
!=
""
&&
detail
!=
dns
1123LabelErrorMsg
{
if
detail
!=
""
&&
detail
!=
DNS
1123LabelErrorMsg
{
t
.
Errorf
(
"%s: expected error detail either empty or %s, got %s"
,
k
,
dns
1123LabelErrorMsg
,
detail
)
t
.
Errorf
(
"%s: expected error detail either empty or %s, got %s"
,
k
,
DNS
1123LabelErrorMsg
,
detail
)
}
}
}
}
}
}
...
@@ -2804,11 +2804,11 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -2804,11 +2804,11 @@ func TestValidateLimitRange(t *testing.T) {
},
},
"invalid Name"
:
{
"invalid Name"
:
{
api
.
LimitRange
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"^Invalid"
,
Namespace
:
"foo"
},
Spec
:
spec
},
api
.
LimitRange
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"^Invalid"
,
Namespace
:
"foo"
},
Spec
:
spec
},
dns
SubdomainErrorMsg
,
DNS
SubdomainErrorMsg
,
},
},
"invalid Namespace"
:
{
"invalid Namespace"
:
{
api
.
LimitRange
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"^Invalid"
},
Spec
:
spec
},
api
.
LimitRange
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"^Invalid"
},
Spec
:
spec
},
dns
1123LabelErrorMsg
,
DNS
1123LabelErrorMsg
,
},
},
"duplicate limit type"
:
{
"duplicate limit type"
:
{
api
.
LimitRange
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
},
Spec
:
invalidSpecDuplicateType
},
api
.
LimitRange
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
},
Spec
:
invalidSpecDuplicateType
},
...
@@ -2879,11 +2879,11 @@ func TestValidateResourceQuota(t *testing.T) {
...
@@ -2879,11 +2879,11 @@ func TestValidateResourceQuota(t *testing.T) {
},
},
"invalid Name"
:
{
"invalid Name"
:
{
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"^Invalid"
,
Namespace
:
"foo"
},
Spec
:
spec
},
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"^Invalid"
,
Namespace
:
"foo"
},
Spec
:
spec
},
dns
SubdomainErrorMsg
,
DNS
SubdomainErrorMsg
,
},
},
"invalid Namespace"
:
{
"invalid Namespace"
:
{
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"^Invalid"
},
Spec
:
spec
},
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"^Invalid"
},
Spec
:
spec
},
dns
1123LabelErrorMsg
,
DNS
1123LabelErrorMsg
,
},
},
}
}
for
k
,
v
:=
range
errorCases
{
for
k
,
v
:=
range
errorCases
{
...
@@ -3341,12 +3341,12 @@ func TestValidateEndpoints(t *testing.T) {
...
@@ -3341,12 +3341,12 @@ func TestValidateEndpoints(t *testing.T) {
"invalid namespace"
:
{
"invalid namespace"
:
{
endpoints
:
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"mysvc"
,
Namespace
:
"no@#invalid.;chars
\"
allowed"
}},
endpoints
:
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"mysvc"
,
Namespace
:
"no@#invalid.;chars
\"
allowed"
}},
errorType
:
"FieldValueInvalid"
,
errorType
:
"FieldValueInvalid"
,
errorDetail
:
dns
1123LabelErrorMsg
,
errorDetail
:
DNS
1123LabelErrorMsg
,
},
},
"invalid name"
:
{
"invalid name"
:
{
endpoints
:
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"-_Invliad^&Characters"
,
Namespace
:
"namespace"
}},
endpoints
:
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"-_Invliad^&Characters"
,
Namespace
:
"namespace"
}},
errorType
:
"FieldValueInvalid"
,
errorType
:
"FieldValueInvalid"
,
errorDetail
:
dns
SubdomainErrorMsg
,
errorDetail
:
DNS
SubdomainErrorMsg
,
},
},
"empty addresses"
:
{
"empty addresses"
:
{
endpoints
:
api
.
Endpoints
{
endpoints
:
api
.
Endpoints
{
...
...
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