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
ff446ece
Commit
ff446ece
authored
Mar 03, 2016
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding a test to make sure the ignore NotFound error patch is working
parent
a3a6130f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
etcd_test.go
pkg/registry/pod/etcd/etcd_test.go
+67
-0
No files found.
pkg/registry/pod/etcd/etcd_test.go
View file @
ff446ece
...
@@ -20,6 +20,8 @@ import (
...
@@ -20,6 +20,8 @@ import (
"strings"
"strings"
"testing"
"testing"
etcd
"github.com/coreos/etcd/client"
"golang.org/x/net/context"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
etcderrors
"k8s.io/kubernetes/pkg/api/errors/etcd"
etcderrors
"k8s.io/kubernetes/pkg/api/errors/etcd"
...
@@ -30,6 +32,7 @@ import (
...
@@ -30,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/securitycontext"
"k8s.io/kubernetes/pkg/securitycontext"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
etcdtesting
"k8s.io/kubernetes/pkg/storage/etcd/testing"
etcdtesting
"k8s.io/kubernetes/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
...
@@ -130,6 +133,70 @@ func TestDelete(t *testing.T) {
...
@@ -130,6 +133,70 @@ func TestDelete(t *testing.T) {
test
.
TestDeleteGraceful
(
scheduledPod
,
30
)
test
.
TestDeleteGraceful
(
scheduledPod
,
30
)
}
}
type
FailDeletionStorage
struct
{
storage
.
Interface
Called
*
bool
}
func
(
f
FailDeletionStorage
)
Delete
(
ctx
context
.
Context
,
key
string
,
out
runtime
.
Object
)
error
{
*
f
.
Called
=
true
return
etcd
.
Error
{
Code
:
etcd
.
ErrorCodeKeyNotFound
}
}
func
newFailDeleteStorage
(
t
*
testing
.
T
,
called
*
bool
)
(
*
REST
,
*
etcdtesting
.
EtcdTestServer
)
{
etcdStorage
,
server
:=
registrytest
.
NewEtcdStorage
(
t
,
""
)
failDeleteStorage
:=
FailDeletionStorage
{
etcdStorage
,
called
}
restOptions
:=
generic
.
RESTOptions
{
failDeleteStorage
,
generic
.
UndecoratedStorage
,
3
}
storage
:=
NewStorage
(
restOptions
,
nil
,
nil
)
return
storage
.
Pod
,
server
}
func
TestIgnoreDeleteNotFound
(
t
*
testing
.
T
)
{
pod
:=
validNewPod
()
testContext
:=
api
.
WithNamespace
(
api
.
NewContext
(),
api
.
NamespaceDefault
)
called
:=
false
registry
,
server
:=
newFailDeleteStorage
(
t
,
&
called
)
defer
server
.
Terminate
(
t
)
// should fail if pod A is not created yet.
_
,
err
:=
registry
.
Delete
(
testContext
,
pod
.
Name
,
nil
)
if
!
errors
.
IsNotFound
(
err
)
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
// create pod
_
,
err
=
registry
.
Create
(
testContext
,
pod
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
// delete object with grace period 0, storage will return NotFound, but the
// registry shouldn't get any error since we ignore the NotFound error.
zero
:=
int64
(
0
)
opt
:=
&
api
.
DeleteOptions
{
GracePeriodSeconds
:
&
zero
}
obj
,
err
:=
registry
.
Delete
(
testContext
,
pod
.
Name
,
opt
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
if
!
called
{
t
.
Fatalf
(
"expect the overriding Delete method to be called"
)
}
deletedPod
,
ok
:=
obj
.
(
*
api
.
Pod
)
if
!
ok
{
t
.
Fatalf
(
"expect a pod is returned"
)
}
if
deletedPod
.
DeletionTimestamp
==
nil
{
t
.
Errorf
(
"expect the DeletionTimestamp to be set"
)
}
if
deletedPod
.
DeletionGracePeriodSeconds
==
nil
{
t
.
Fatalf
(
"expect the DeletionGracePeriodSeconds to be set"
)
}
if
*
deletedPod
.
DeletionGracePeriodSeconds
!=
0
{
t
.
Errorf
(
"expect the DeletionGracePeriodSeconds to be 0, got %d"
,
*
deletedPod
.
DeletionTimestamp
)
}
}
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
storage
,
_
,
_
,
server
:=
newStorage
(
t
)
storage
,
_
,
_
,
server
:=
newStorage
(
t
)
defer
server
.
Terminate
(
t
)
defer
server
.
Terminate
(
t
)
...
...
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