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
61175929
Commit
61175929
authored
Feb 12, 2015
by
Zach Loafman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add expectNoError helper to handle Expect(err).NotTo(HaveOccurred()) meme
And convert one file
parent
62ff4348
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
14 deletions
+15
-14
pods.go
test/e2e/pods.go
+10
-14
util.go
test/e2e/util.go
+5
-0
No files found.
test/e2e/pods.go
View file @
61175929
...
@@ -35,7 +35,7 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) {
...
@@ -35,7 +35,7 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) {
By
(
fmt
.
Sprintf
(
"Creating pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
By
(
fmt
.
Sprintf
(
"Creating pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
_
,
err
:=
c
.
Pods
(
ns
)
.
Create
(
podDescr
)
_
,
err
:=
c
.
Pods
(
ns
)
.
Create
(
podDescr
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
()
,
fmt
.
Sprintf
(
"creating pod %s"
,
podDescr
.
Name
))
expectNoError
(
err
,
fmt
.
Sprintf
(
"creating pod %s"
,
podDescr
.
Name
))
// At the end of the test, clean up by removing the pod.
// At the end of the test, clean up by removing the pod.
defer
func
()
{
defer
func
()
{
...
@@ -47,14 +47,14 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) {
...
@@ -47,14 +47,14 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) {
// 'Pending' other than checking for 'Running', since when failures occur, we go to
// 'Pending' other than checking for 'Running', since when failures occur, we go to
// 'Terminated' which can cause indefinite blocking.)
// 'Terminated' which can cause indefinite blocking.)
By
(
"waiting for the pod to be something other than pending"
)
By
(
"waiting for the pod to be something other than pending"
)
e
rr
=
waitForPodNotPending
(
c
,
ns
,
podDescr
.
Name
,
60
*
time
.
Second
)
e
xpectNoError
(
waitForPodNotPending
(
c
,
ns
,
podDescr
.
Name
,
60
*
time
.
Second
),
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
fmt
.
Sprintf
(
"starting pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
fmt
.
Sprintf
(
"starting pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
By
(
fmt
.
Sprintf
(
"Started pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
By
(
fmt
.
Sprintf
(
"Started pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
// Check the pod's current state and verify that restartCount is present.
// Check the pod's current state and verify that restartCount is present.
By
(
"checking the pod's current state and verifying that restartCount is present"
)
By
(
"checking the pod's current state and verifying that restartCount is present"
)
pod
,
err
:=
c
.
Pods
(
ns
)
.
Get
(
podDescr
.
Name
)
pod
,
err
:=
c
.
Pods
(
ns
)
.
Get
(
podDescr
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
()
,
fmt
.
Sprintf
(
"getting pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
expectNoError
(
err
,
fmt
.
Sprintf
(
"getting pod %s in namespace %s"
,
podDescr
.
Name
,
ns
))
initialRestartCount
:=
pod
.
Status
.
Info
[
"liveness"
]
.
RestartCount
initialRestartCount
:=
pod
.
Status
.
Info
[
"liveness"
]
.
RestartCount
By
(
fmt
.
Sprintf
(
"Initial restart count of pod %s is %d"
,
podDescr
.
Name
,
initialRestartCount
))
By
(
fmt
.
Sprintf
(
"Initial restart count of pod %s is %d"
,
podDescr
.
Name
,
initialRestartCount
))
...
@@ -64,7 +64,7 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) {
...
@@ -64,7 +64,7 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) {
// Wait until restartCount is incremented.
// Wait until restartCount is incremented.
time
.
Sleep
(
5
*
time
.
Second
)
time
.
Sleep
(
5
*
time
.
Second
)
pod
,
err
=
c
.
Pods
(
ns
)
.
Get
(
podDescr
.
Name
)
pod
,
err
=
c
.
Pods
(
ns
)
.
Get
(
podDescr
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
()
,
fmt
.
Sprintf
(
"getting pod %s"
,
podDescr
.
Name
))
expectNoError
(
err
,
fmt
.
Sprintf
(
"getting pod %s"
,
podDescr
.
Name
))
restartCount
:=
pod
.
Status
.
Info
[
"liveness"
]
.
RestartCount
restartCount
:=
pod
.
Status
.
Info
[
"liveness"
]
.
RestartCount
By
(
fmt
.
Sprintf
(
"Restart count of pod %s in namespace %s is now %d"
,
podDescr
.
Name
,
ns
,
restartCount
))
By
(
fmt
.
Sprintf
(
"Restart count of pod %s in namespace %s is now %d"
,
podDescr
.
Name
,
ns
,
restartCount
))
if
restartCount
>
initialRestartCount
{
if
restartCount
>
initialRestartCount
{
...
@@ -85,7 +85,7 @@ var _ = Describe("Pods", func() {
...
@@ -85,7 +85,7 @@ var _ = Describe("Pods", func() {
BeforeEach
(
func
()
{
BeforeEach
(
func
()
{
var
err
error
var
err
error
c
,
err
=
loadClient
()
c
,
err
=
loadClient
()
Expect
(
err
)
.
NotTo
(
HaveOccurred
()
)
expectNoError
(
err
)
})
})
It
(
"should be submitted and removed"
,
func
()
{
It
(
"should be submitted and removed"
,
func
()
{
...
@@ -192,8 +192,7 @@ var _ = Describe("Pods", func() {
...
@@ -192,8 +192,7 @@ var _ = Describe("Pods", func() {
}()
}()
By
(
"waiting for the pod to start running"
)
By
(
"waiting for the pod to start running"
)
err
=
waitForPodRunning
(
c
,
pod
.
Name
,
300
*
time
.
Second
)
expectNoError
(
waitForPodRunning
(
c
,
pod
.
Name
,
300
*
time
.
Second
))
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"verifying the pod is in kubernetes"
)
By
(
"verifying the pod is in kubernetes"
)
pods
,
err
:=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})))
pods
,
err
:=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})))
...
@@ -216,8 +215,7 @@ var _ = Describe("Pods", func() {
...
@@ -216,8 +215,7 @@ var _ = Describe("Pods", func() {
}
}
By
(
"waiting for the updated pod to start running"
)
By
(
"waiting for the updated pod to start running"
)
err
=
waitForPodRunning
(
c
,
pod
.
Name
,
300
*
time
.
Second
)
expectNoError
(
waitForPodRunning
(
c
,
pod
.
Name
,
300
*
time
.
Second
))
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"verifying the updated pod is in kubernetes"
)
By
(
"verifying the updated pod is in kubernetes"
)
pods
,
err
=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})))
pods
,
err
=
podClient
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"time"
:
value
})))
...
@@ -251,8 +249,7 @@ var _ = Describe("Pods", func() {
...
@@ -251,8 +249,7 @@ var _ = Describe("Pods", func() {
defer
func
()
{
defer
func
()
{
c
.
Pods
(
api
.
NamespaceDefault
)
.
Delete
(
serverPod
.
Name
)
c
.
Pods
(
api
.
NamespaceDefault
)
.
Delete
(
serverPod
.
Name
)
}()
}()
err
=
waitForPodRunning
(
c
,
serverPod
.
Name
,
300
*
time
.
Second
)
expectNoError
(
waitForPodRunning
(
c
,
serverPod
.
Name
,
300
*
time
.
Second
))
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
// This service exposes port 8080 of the test pod as a service on port 8765
// This service exposes port 8080 of the test pod as a service on port 8765
// TODO(filbranden): We would like to use a unique service name such as:
// TODO(filbranden): We would like to use a unique service name such as:
...
@@ -317,8 +314,7 @@ var _ = Describe("Pods", func() {
...
@@ -317,8 +314,7 @@ var _ = Describe("Pods", func() {
}()
}()
// Wait for client pod to complete.
// Wait for client pod to complete.
err
=
waitForPodSuccess
(
c
,
clientPod
.
Name
,
clientPod
.
Spec
.
Containers
[
0
]
.
Name
,
60
*
time
.
Second
)
expectNoError
(
waitForPodSuccess
(
c
,
clientPod
.
Name
,
clientPod
.
Spec
.
Containers
[
0
]
.
Name
,
60
*
time
.
Second
))
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
// Grab its logs. Get host first.
// Grab its logs. Get host first.
clientPodStatus
,
err
:=
c
.
Pods
(
api
.
NamespaceDefault
)
.
Get
(
clientPod
.
Name
)
clientPodStatus
,
err
:=
c
.
Pods
(
api
.
NamespaceDefault
)
.
Get
(
clientPod
.
Name
)
...
...
test/e2e/util.go
View file @
61175929
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
)
type
testContextType
struct
{
type
testContextType
struct
{
...
@@ -152,3 +153,7 @@ func randomSuffix() string {
...
@@ -152,3 +153,7 @@ func randomSuffix() string {
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
return
strconv
.
Itoa
(
r
.
Int
()
%
10000
)
return
strconv
.
Itoa
(
r
.
Int
()
%
10000
)
}
}
func
expectNoError
(
err
error
,
explain
...
interface
{})
{
ExpectWithOffset
(
1
,
err
)
.
NotTo
(
HaveOccurred
(),
explain
...
)
}
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