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
4b9588cc
Commit
4b9588cc
authored
Sep 12, 2017
by
wackxu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for some function
parent
d7ec46c5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
227 additions
and
0 deletions
+227
-0
BUILD
pkg/apis/core/v1/validation/BUILD
+2
-0
validation_test.go
pkg/apis/core/v1/validation/validation_test.go
+225
-0
No files found.
pkg/apis/core/v1/validation/BUILD
View file @
4b9588cc
...
@@ -23,6 +23,8 @@ go_test(
...
@@ -23,6 +23,8 @@ go_test(
deps = [
deps = [
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
],
],
)
)
...
...
pkg/apis/core/v1/validation/validation_test.go
View file @
4b9588cc
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
)
)
...
@@ -177,3 +179,226 @@ func TestValidateResourceRequirements(t *testing.T) {
...
@@ -177,3 +179,226 @@ func TestValidateResourceRequirements(t *testing.T) {
}
}
}
}
}
}
func
TestValidatePodLogOptions
(
t
*
testing
.
T
)
{
var
(
positiveLine
=
int64
(
8
)
negativeLine
=
int64
(
-
8
)
limitBytesGreaterThan1
=
int64
(
12
)
limitBytesLessThan1
=
int64
(
0
)
sinceSecondsGreaterThan1
=
int64
(
10
)
sinceSecondsLessThan1
=
int64
(
0
)
timestamp
=
metav1
.
Now
()
)
successCase
:=
[]
struct
{
Name
string
podLogOptions
v1
.
PodLogOptions
}{
{
Name
:
"Empty PodLogOptions"
,
podLogOptions
:
v1
.
PodLogOptions
{},
},
{
Name
:
"PodLogOptions with TailLines"
,
podLogOptions
:
v1
.
PodLogOptions
{
TailLines
:
&
positiveLine
,
},
},
{
Name
:
"PodLogOptions with LimitBytes"
,
podLogOptions
:
v1
.
PodLogOptions
{
LimitBytes
:
&
limitBytesGreaterThan1
,
},
},
{
Name
:
"PodLogOptions with only sinceSeconds"
,
podLogOptions
:
v1
.
PodLogOptions
{
SinceSeconds
:
&
sinceSecondsGreaterThan1
,
},
},
{
Name
:
"PodLogOptions with LimitBytes with TailLines"
,
podLogOptions
:
v1
.
PodLogOptions
{
LimitBytes
:
&
limitBytesGreaterThan1
,
TailLines
:
&
positiveLine
,
},
},
{
Name
:
"PodLogOptions with LimitBytes with TailLines with SinceSeconds"
,
podLogOptions
:
v1
.
PodLogOptions
{
LimitBytes
:
&
limitBytesGreaterThan1
,
TailLines
:
&
positiveLine
,
SinceSeconds
:
&
sinceSecondsGreaterThan1
,
},
},
}
for
_
,
tc
:=
range
successCase
{
if
errs
:=
ValidatePodLogOptions
(
&
tc
.
podLogOptions
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"%q unexpected error: %v"
,
tc
.
Name
,
errs
)
}
}
errorCase
:=
[]
struct
{
Name
string
podLogOptions
v1
.
PodLogOptions
}{
{
Name
:
"Invalid podLogOptions with Negative TailLines"
,
podLogOptions
:
v1
.
PodLogOptions
{
TailLines
:
&
negativeLine
,
LimitBytes
:
&
limitBytesGreaterThan1
,
SinceSeconds
:
&
sinceSecondsGreaterThan1
,
},
},
{
Name
:
"Invalid podLogOptions with zero or negative LimitBytes"
,
podLogOptions
:
v1
.
PodLogOptions
{
TailLines
:
&
positiveLine
,
LimitBytes
:
&
limitBytesLessThan1
,
SinceSeconds
:
&
sinceSecondsGreaterThan1
,
},
},
{
Name
:
"Invalid podLogOptions with zero or negative SinceSeconds"
,
podLogOptions
:
v1
.
PodLogOptions
{
TailLines
:
&
negativeLine
,
LimitBytes
:
&
limitBytesGreaterThan1
,
SinceSeconds
:
&
sinceSecondsLessThan1
,
},
},
{
Name
:
"Invalid podLogOptions with both SinceSeconds and SinceTime set"
,
podLogOptions
:
v1
.
PodLogOptions
{
TailLines
:
&
negativeLine
,
LimitBytes
:
&
limitBytesGreaterThan1
,
SinceSeconds
:
&
sinceSecondsGreaterThan1
,
SinceTime
:
&
timestamp
,
},
},
}
for
_
,
tc
:=
range
errorCase
{
if
errs
:=
ValidatePodLogOptions
(
&
tc
.
podLogOptions
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"%q expected error"
,
tc
.
Name
)
}
}
}
func
TestAccumulateUniqueHostPorts
(
t
*
testing
.
T
)
{
successCase
:=
[]
struct
{
containers
[]
v1
.
Container
accumulator
*
sets
.
String
fldPath
*
field
.
Path
result
string
}{
{
containers
:
[]
v1
.
Container
{
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8080
,
Protocol
:
v1
.
ProtocolUDP
,
},
},
},
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8080
,
Protocol
:
v1
.
ProtocolTCP
,
},
},
},
},
accumulator
:
&
sets
.
String
{},
fldPath
:
field
.
NewPath
(
"spec"
,
"containers"
),
result
:
"HostPort is not allocated"
,
},
{
containers
:
[]
v1
.
Container
{
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8080
,
Protocol
:
v1
.
ProtocolUDP
,
},
},
},
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8081
,
Protocol
:
v1
.
ProtocolUDP
,
},
},
},
},
accumulator
:
&
sets
.
String
{},
fldPath
:
field
.
NewPath
(
"spec"
,
"containers"
),
result
:
"HostPort is not allocated"
,
},
}
for
index
,
tc
:=
range
successCase
{
if
errs
:=
AccumulateUniqueHostPorts
(
tc
.
containers
,
tc
.
accumulator
,
tc
.
fldPath
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"unexpected error for test case %v: %v"
,
index
,
errs
)
}
}
errorCase
:=
[]
struct
{
containers
[]
v1
.
Container
accumulator
*
sets
.
String
fldPath
*
field
.
Path
result
string
}{
{
containers
:
[]
v1
.
Container
{
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8080
,
Protocol
:
v1
.
ProtocolUDP
,
},
},
},
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8080
,
Protocol
:
v1
.
ProtocolUDP
,
},
},
},
},
accumulator
:
&
sets
.
String
{},
fldPath
:
field
.
NewPath
(
"spec"
,
"containers"
),
result
:
"HostPort is already allocated"
,
},
{
containers
:
[]
v1
.
Container
{
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8080
,
Protocol
:
v1
.
ProtocolUDP
,
},
},
},
{
Ports
:
[]
v1
.
ContainerPort
{
{
HostPort
:
8081
,
Protocol
:
v1
.
ProtocolUDP
,
},
},
},
},
accumulator
:
&
sets
.
String
{
"8080/UDP"
:
sets
.
Empty
{}},
fldPath
:
field
.
NewPath
(
"spec"
,
"containers"
),
result
:
"HostPort is already allocated"
,
},
}
for
index
,
tc
:=
range
errorCase
{
if
errs
:=
AccumulateUniqueHostPorts
(
tc
.
containers
,
tc
.
accumulator
,
tc
.
fldPath
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"test case %v: expected error %v, but get nil"
,
index
,
tc
.
result
)
}
}
}
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