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
fc09f988
Commit
fc09f988
authored
Sep 07, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make tests pass again
parent
48ce23ac
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
270 additions
and
228 deletions
+270
-228
integration.go
cmd/integration/integration.go
+3
-3
kubecfg.go
cmd/kubecfg/kubecfg.go
+5
-5
apiserver_test.go
pkg/apiserver/apiserver_test.go
+40
-33
operation_test.go
pkg/apiserver/operation_test.go
+8
-7
watch_test.go
pkg/apiserver/watch_test.go
+4
-3
fake.go
pkg/client/fake.go
+1
-1
replication_controller_test.go
pkg/controller/replication_controller_test.go
+4
-4
etcd_master.go
pkg/election/etcd_master.go
+10
-1
etcd_master_test.go
pkg/election/etcd_master_test.go
+3
-3
kubecfg_test.go
pkg/kubecfg/kubecfg_test.go
+6
-6
parse.go
pkg/kubecfg/parse.go
+3
-2
parse_test.go
pkg/kubecfg/parse_test.go
+16
-14
resource_printer.go
pkg/kubecfg/resource_printer.go
+1
-1
resource_printer_test.go
pkg/kubecfg/resource_printer_test.go
+9
-5
etcd_test.go
pkg/registry/etcd/etcd_test.go
+36
-36
storage_test.go
pkg/registry/minion/storage_test.go
+5
-5
storage_test.go
pkg/registry/pod/storage_test.go
+2
-2
controller.go
pkg/registry/registrytest/controller.go
+2
-2
pod.go
pkg/registry/registrytest/pod.go
+6
-6
service.go
pkg/registry/registrytest/service.go
+6
-6
storage_test.go
pkg/registry/service/storage_test.go
+8
-8
etcd_tools_test.go
pkg/tools/etcd_tools_test.go
+15
-15
etcd_tools_watch_test.go
pkg/tools/etcd_tools_watch_test.go
+24
-24
filter.go
pkg/watch/filter.go
+5
-0
filter_test.go
pkg/watch/filter_test.go
+10
-10
iowatcher_test.go
pkg/watch/iowatcher_test.go
+4
-2
watch_test.go
pkg/watch/watch_test.go
+14
-10
factory_test.go
plugin/pkg/scheduler/factory/factory_test.go
+3
-3
client_test.go
test/integration/client_test.go
+1
-1
etcd_tools_test.go
test/integration/etcd_tools_test.go
+16
-10
No files found.
cmd/integration/integration.go
View file @
fc09f988
...
@@ -179,7 +179,7 @@ func runReplicationControllerTest(c *client.Client) {
...
@@ -179,7 +179,7 @@ func runReplicationControllerTest(c *client.Client) {
}
}
glog
.
Infof
(
"Creating replication controllers"
)
glog
.
Infof
(
"Creating replication controllers"
)
if
_
,
err
:=
c
.
CreateReplicationController
(
controllerRequest
);
err
!=
nil
{
if
_
,
err
:=
c
.
CreateReplicationController
(
&
controllerRequest
);
err
!=
nil
{
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
}
}
glog
.
Infof
(
"Done creating replication controllers"
)
glog
.
Infof
(
"Done creating replication controllers"
)
...
@@ -194,7 +194,7 @@ func runReplicationControllerTest(c *client.Client) {
...
@@ -194,7 +194,7 @@ func runReplicationControllerTest(c *client.Client) {
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"FAILED: unable to get pods to list: %v"
,
err
)
glog
.
Fatalf
(
"FAILED: unable to get pods to list: %v"
,
err
)
}
}
if
err
:=
wait
.
Poll
(
time
.
Second
,
time
.
Second
*
10
,
podsOnMinions
(
c
,
pods
));
err
!=
nil
{
if
err
:=
wait
.
Poll
(
time
.
Second
,
time
.
Second
*
10
,
podsOnMinions
(
c
,
*
pods
));
err
!=
nil
{
glog
.
Fatalf
(
"FAILED: pods never started running %v"
,
err
)
glog
.
Fatalf
(
"FAILED: pods never started running %v"
,
err
)
}
}
...
@@ -204,7 +204,7 @@ func runReplicationControllerTest(c *client.Client) {
...
@@ -204,7 +204,7 @@ func runReplicationControllerTest(c *client.Client) {
func
runAtomicPutTest
(
c
*
client
.
Client
)
{
func
runAtomicPutTest
(
c
*
client
.
Client
)
{
var
svc
api
.
Service
var
svc
api
.
Service
err
:=
c
.
Post
()
.
Path
(
"services"
)
.
Body
(
err
:=
c
.
Post
()
.
Path
(
"services"
)
.
Body
(
api
.
Service
{
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"atomicservice"
,
APIVersion
:
"v1beta1"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"atomicservice"
,
APIVersion
:
"v1beta1"
},
Port
:
12345
,
Port
:
12345
,
Labels
:
map
[
string
]
string
{
Labels
:
map
[
string
]
string
{
...
...
cmd/kubecfg/kubecfg.go
View file @
fc09f988
...
@@ -58,11 +58,11 @@ var (
...
@@ -58,11 +58,11 @@ var (
imageName
=
flag
.
String
(
"image"
,
""
,
"Image used when updating a replicationController. Will apply to the first container in the pod template."
)
imageName
=
flag
.
String
(
"image"
,
""
,
"Image used when updating a replicationController. Will apply to the first container in the pod template."
)
)
)
var
parser
=
kubecfg
.
NewParser
(
map
[
string
]
interface
{}
{
var
parser
=
kubecfg
.
NewParser
(
map
[
string
]
runtime
.
Object
{
"pods"
:
api
.
Pod
{},
"pods"
:
&
api
.
Pod
{},
"services"
:
api
.
Service
{},
"services"
:
&
api
.
Service
{},
"replicationControllers"
:
api
.
ReplicationController
{},
"replicationControllers"
:
&
api
.
ReplicationController
{},
"minions"
:
api
.
Minion
{},
"minions"
:
&
api
.
Minion
{},
})
})
func
usage
()
{
func
usage
()
{
...
...
pkg/apiserver/apiserver_test.go
View file @
fc09f988
...
@@ -38,15 +38,15 @@ import (
...
@@ -38,15 +38,15 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
)
func
convert
(
obj
interface
{})
(
interface
{}
,
error
)
{
func
convert
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
obj
,
nil
return
obj
,
nil
}
}
var
codec
=
runtime
.
DefaultCodec
var
codec
=
runtime
.
DefaultCodec
func
init
()
{
func
init
()
{
runtime
.
AddKnownTypes
(
""
,
Simple
{},
SimpleList
{})
runtime
.
DefaultScheme
.
AddKnownTypes
(
""
,
&
Simple
{},
&
SimpleList
{})
runtime
.
AddKnownTypes
(
"v1beta1"
,
Simple
{},
SimpleList
{})
runtime
.
DefaultScheme
.
AddKnownTypes
(
"v1beta1"
,
&
Simple
{},
&
SimpleList
{})
}
}
type
Simple
struct
{
type
Simple
struct
{
...
@@ -54,11 +54,15 @@ type Simple struct {
...
@@ -54,11 +54,15 @@ type Simple struct {
Name
string
`yaml:"name,omitempty" json:"name,omitempty"`
Name
string
`yaml:"name,omitempty" json:"name,omitempty"`
}
}
func
(
*
Simple
)
IsAnAPIObject
()
{}
type
SimpleList
struct
{
type
SimpleList
struct
{
api
.
JSONBase
`yaml:",inline" json:",inline"`
api
.
JSONBase
`yaml:",inline" json:",inline"`
Items
[]
Simple
`yaml:"items,omitempty" json:"items,omitempty"`
Items
[]
Simple
`yaml:"items,omitempty" json:"items,omitempty"`
}
}
func
(
*
SimpleList
)
IsAnAPIObject
()
{}
type
SimpleRESTStorage
struct
{
type
SimpleRESTStorage
struct
{
errors
map
[
string
]
error
errors
map
[
string
]
error
list
[]
Simple
list
[]
Simple
...
@@ -78,43 +82,43 @@ type SimpleRESTStorage struct {
...
@@ -78,43 +82,43 @@ type SimpleRESTStorage struct {
// If non-nil, called inside the WorkFunc when answering update, delete, create.
// If non-nil, called inside the WorkFunc when answering update, delete, create.
// obj receives the original input to the update, delete, or create call.
// obj receives the original input to the update, delete, or create call.
injectedFunction
func
(
obj
interface
{})
(
returnObj
interface
{}
,
err
error
)
injectedFunction
func
(
obj
runtime
.
Object
)
(
returnObj
runtime
.
Object
,
err
error
)
}
}
func
(
storage
*
SimpleRESTStorage
)
List
(
labels
.
Selector
)
(
interface
{}
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
List
(
labels
.
Selector
)
(
runtime
.
Object
,
error
)
{
result
:=
&
SimpleList
{
result
:=
&
SimpleList
{
Items
:
storage
.
list
,
Items
:
storage
.
list
,
}
}
return
result
,
storage
.
errors
[
"list"
]
return
result
,
storage
.
errors
[
"list"
]
}
}
func
(
storage
*
SimpleRESTStorage
)
Get
(
id
string
)
(
interface
{}
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Get
(
id
string
)
(
runtime
.
Object
,
error
)
{
return
storage
.
item
,
storage
.
errors
[
"get"
]
return
runtime
.
DefaultScheme
.
CopyOrDie
(
&
storage
.
item
)
,
storage
.
errors
[
"get"
]
}
}
func
(
storage
*
SimpleRESTStorage
)
Delete
(
id
string
)
(
<-
chan
interface
{}
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Delete
(
id
string
)
(
<-
chan
runtime
.
Object
,
error
)
{
storage
.
deleted
=
id
storage
.
deleted
=
id
if
err
:=
storage
.
errors
[
"delete"
];
err
!=
nil
{
if
err
:=
storage
.
errors
[
"delete"
];
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
MakeAsync
(
func
()
(
interface
{}
,
error
)
{
return
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
if
storage
.
injectedFunction
!=
nil
{
if
storage
.
injectedFunction
!=
nil
{
return
storage
.
injectedFunction
(
id
)
return
storage
.
injectedFunction
(
&
Simple
{
JSONBase
:
api
.
JSONBase
{
ID
:
id
}}
)
}
}
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
nil
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
nil
}),
nil
}),
nil
}
}
func
(
storage
*
SimpleRESTStorage
)
New
()
interface
{}
{
func
(
storage
*
SimpleRESTStorage
)
New
()
runtime
.
Object
{
return
&
Simple
{}
return
&
Simple
{}
}
}
func
(
storage
*
SimpleRESTStorage
)
Create
(
obj
interface
{})
(
<-
chan
interface
{}
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Create
(
obj
runtime
.
Object
)
(
<-
chan
runtime
.
Object
,
error
)
{
storage
.
created
=
obj
.
(
*
Simple
)
storage
.
created
=
obj
.
(
*
Simple
)
if
err
:=
storage
.
errors
[
"create"
];
err
!=
nil
{
if
err
:=
storage
.
errors
[
"create"
];
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
MakeAsync
(
func
()
(
interface
{}
,
error
)
{
return
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
if
storage
.
injectedFunction
!=
nil
{
if
storage
.
injectedFunction
!=
nil
{
return
storage
.
injectedFunction
(
obj
)
return
storage
.
injectedFunction
(
obj
)
}
}
...
@@ -122,12 +126,12 @@ func (storage *SimpleRESTStorage) Create(obj interface{}) (<-chan interface{}, e
...
@@ -122,12 +126,12 @@ func (storage *SimpleRESTStorage) Create(obj interface{}) (<-chan interface{}, e
}),
nil
}),
nil
}
}
func
(
storage
*
SimpleRESTStorage
)
Update
(
obj
interface
{})
(
<-
chan
interface
{}
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Update
(
obj
runtime
.
Object
)
(
<-
chan
runtime
.
Object
,
error
)
{
storage
.
updated
=
obj
.
(
*
Simple
)
storage
.
updated
=
obj
.
(
*
Simple
)
if
err
:=
storage
.
errors
[
"update"
];
err
!=
nil
{
if
err
:=
storage
.
errors
[
"update"
];
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
MakeAsync
(
func
()
(
interface
{}
,
error
)
{
return
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
if
storage
.
injectedFunction
!=
nil
{
if
storage
.
injectedFunction
!=
nil
{
return
storage
.
injectedFunction
(
obj
)
return
storage
.
injectedFunction
(
obj
)
}
}
...
@@ -156,7 +160,7 @@ func (storage *SimpleRESTStorage) ResourceLocation(id string) (string, error) {
...
@@ -156,7 +160,7 @@ func (storage *SimpleRESTStorage) ResourceLocation(id string) (string, error) {
return
id
,
nil
return
id
,
nil
}
}
func
extractBody
(
response
*
http
.
Response
,
object
interface
{}
)
(
string
,
error
)
{
func
extractBody
(
response
*
http
.
Response
,
object
runtime
.
Object
)
(
string
,
error
)
{
defer
response
.
Body
.
Close
()
defer
response
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
response
.
Body
)
body
,
err
:=
ioutil
.
ReadAll
(
response
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -398,7 +402,7 @@ func TestUpdate(t *testing.T) {
...
@@ -398,7 +402,7 @@ func TestUpdate(t *testing.T) {
handler
:=
Handle
(
storage
,
codec
,
"/prefix/version"
)
handler
:=
Handle
(
storage
,
codec
,
"/prefix/version"
)
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
item
:=
Simple
{
item
:=
&
Simple
{
Name
:
"bar"
,
Name
:
"bar"
,
}
}
body
,
err
:=
codec
.
Encode
(
item
)
body
,
err
:=
codec
.
Encode
(
item
)
...
@@ -428,7 +432,7 @@ func TestUpdateMissing(t *testing.T) {
...
@@ -428,7 +432,7 @@ func TestUpdateMissing(t *testing.T) {
handler
:=
Handle
(
storage
,
codec
,
"/prefix/version"
)
handler
:=
Handle
(
storage
,
codec
,
"/prefix/version"
)
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
item
:=
Simple
{
item
:=
&
Simple
{
Name
:
"bar"
,
Name
:
"bar"
,
}
}
body
,
err
:=
codec
.
Encode
(
item
)
body
,
err
:=
codec
.
Encode
(
item
)
...
@@ -457,7 +461,7 @@ func TestCreate(t *testing.T) {
...
@@ -457,7 +461,7 @@ func TestCreate(t *testing.T) {
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
client
:=
http
.
Client
{}
client
:=
http
.
Client
{}
simple
:=
Simple
{
simple
:=
&
Simple
{
Name
:
"foo"
,
Name
:
"foo"
,
}
}
data
,
_
:=
codec
.
Encode
(
simple
)
data
,
_
:=
codec
.
Encode
(
simple
)
...
@@ -497,7 +501,7 @@ func TestCreateNotFound(t *testing.T) {
...
@@ -497,7 +501,7 @@ func TestCreateNotFound(t *testing.T) {
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
client
:=
http
.
Client
{}
client
:=
http
.
Client
{}
simple
:=
Simple
{
Name
:
"foo"
}
simple
:=
&
Simple
{
Name
:
"foo"
}
data
,
_
:=
codec
.
Encode
(
simple
)
data
,
_
:=
codec
.
Encode
(
simple
)
request
,
err
:=
http
.
NewRequest
(
"POST"
,
server
.
URL
+
"/prefix/version/simple"
,
bytes
.
NewBuffer
(
data
))
request
,
err
:=
http
.
NewRequest
(
"POST"
,
server
.
URL
+
"/prefix/version/simple"
,
bytes
.
NewBuffer
(
data
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -528,7 +532,7 @@ func TestParseTimeout(t *testing.T) {
...
@@ -528,7 +532,7 @@ func TestParseTimeout(t *testing.T) {
func
TestSyncCreate
(
t
*
testing
.
T
)
{
func
TestSyncCreate
(
t
*
testing
.
T
)
{
storage
:=
SimpleRESTStorage
{
storage
:=
SimpleRESTStorage
{
injectedFunction
:
func
(
obj
interface
{})
(
interface
{}
,
error
)
{
injectedFunction
:
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
time
.
Sleep
(
5
*
time
.
Millisecond
)
time
.
Sleep
(
5
*
time
.
Millisecond
)
return
obj
,
nil
return
obj
,
nil
},
},
...
@@ -539,7 +543,7 @@ func TestSyncCreate(t *testing.T) {
...
@@ -539,7 +543,7 @@ func TestSyncCreate(t *testing.T) {
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
client
:=
http
.
Client
{}
client
:=
http
.
Client
{}
simple
:=
Simple
{
simple
:=
&
Simple
{
Name
:
"foo"
,
Name
:
"foo"
,
}
}
data
,
_
:=
codec
.
Encode
(
simple
)
data
,
_
:=
codec
.
Encode
(
simple
)
...
@@ -566,7 +570,7 @@ func TestSyncCreate(t *testing.T) {
...
@@ -566,7 +570,7 @@ func TestSyncCreate(t *testing.T) {
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
if
!
reflect
.
DeepEqual
(
itemOut
,
simple
)
{
if
!
reflect
.
DeepEqual
(
&
itemOut
,
simple
)
{
t
.
Errorf
(
"Unexpected data: %#v, expected %#v (%s)"
,
itemOut
,
simple
,
string
(
body
))
t
.
Errorf
(
"Unexpected data: %#v, expected %#v (%s)"
,
itemOut
,
simple
,
string
(
body
))
}
}
if
response
.
StatusCode
!=
http
.
StatusOK
{
if
response
.
StatusCode
!=
http
.
StatusOK
{
...
@@ -600,7 +604,7 @@ func expectApiStatus(t *testing.T, method, url string, data []byte, code int) *a
...
@@ -600,7 +604,7 @@ func expectApiStatus(t *testing.T, method, url string, data []byte, code int) *a
func
TestAsyncDelayReturnsError
(
t
*
testing
.
T
)
{
func
TestAsyncDelayReturnsError
(
t
*
testing
.
T
)
{
storage
:=
SimpleRESTStorage
{
storage
:=
SimpleRESTStorage
{
injectedFunction
:
func
(
obj
interface
{})
(
interface
{}
,
error
)
{
injectedFunction
:
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
nil
,
apierrs
.
NewAlreadyExists
(
"foo"
,
"bar"
)
return
nil
,
apierrs
.
NewAlreadyExists
(
"foo"
,
"bar"
)
},
},
}
}
...
@@ -617,7 +621,7 @@ func TestAsyncDelayReturnsError(t *testing.T) {
...
@@ -617,7 +621,7 @@ func TestAsyncDelayReturnsError(t *testing.T) {
func
TestAsyncCreateError
(
t
*
testing
.
T
)
{
func
TestAsyncCreateError
(
t
*
testing
.
T
)
{
ch
:=
make
(
chan
struct
{})
ch
:=
make
(
chan
struct
{})
storage
:=
SimpleRESTStorage
{
storage
:=
SimpleRESTStorage
{
injectedFunction
:
func
(
obj
interface
{})
(
interface
{}
,
error
)
{
injectedFunction
:
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
<-
ch
<-
ch
return
nil
,
apierrs
.
NewAlreadyExists
(
"foo"
,
"bar"
)
return
nil
,
apierrs
.
NewAlreadyExists
(
"foo"
,
"bar"
)
},
},
...
@@ -626,7 +630,7 @@ func TestAsyncCreateError(t *testing.T) {
...
@@ -626,7 +630,7 @@ func TestAsyncCreateError(t *testing.T) {
handler
.
(
*
defaultAPIServer
)
.
group
.
handler
.
asyncOpWait
=
0
handler
.
(
*
defaultAPIServer
)
.
group
.
handler
.
asyncOpWait
=
0
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
simple
:=
Simple
{
Name
:
"foo"
}
simple
:=
&
Simple
{
Name
:
"foo"
}
data
,
_
:=
codec
.
Encode
(
simple
)
data
,
_
:=
codec
.
Encode
(
simple
)
status
:=
expectApiStatus
(
t
,
"POST"
,
fmt
.
Sprintf
(
"%s/prefix/version/foo"
,
server
.
URL
),
data
,
http
.
StatusAccepted
)
status
:=
expectApiStatus
(
t
,
"POST"
,
fmt
.
Sprintf
(
"%s/prefix/version/foo"
,
server
.
URL
),
data
,
http
.
StatusAccepted
)
...
@@ -662,18 +666,21 @@ func TestAsyncCreateError(t *testing.T) {
...
@@ -662,18 +666,21 @@ func TestAsyncCreateError(t *testing.T) {
}
}
}
}
type
UnregisteredAPIObject
struct
{
Value
string
}
func
(
*
UnregisteredAPIObject
)
IsAnAPIObject
()
{}
func
TestWriteJSONDecodeError
(
t
*
testing
.
T
)
{
func
TestWriteJSONDecodeError
(
t
*
testing
.
T
)
{
server
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
server
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
type
T
struct
{
writeJSON
(
http
.
StatusOK
,
runtime
.
DefaultCodec
,
&
UnregisteredAPIObject
{
"Undecodable"
},
w
)
Value
string
}
writeJSON
(
http
.
StatusOK
,
runtime
.
DefaultCodec
,
&
T
{
"Undecodable"
},
w
)
}))
}))
status
:=
expectApiStatus
(
t
,
"GET"
,
server
.
URL
,
nil
,
http
.
StatusInternalServerError
)
status
:=
expectApiStatus
(
t
,
"GET"
,
server
.
URL
,
nil
,
http
.
StatusInternalServerError
)
if
status
.
Reason
!=
api
.
StatusReasonUnknown
{
if
status
.
Reason
!=
api
.
StatusReasonUnknown
{
t
.
Errorf
(
"unexpected reason %#v"
,
status
)
t
.
Errorf
(
"unexpected reason %#v"
,
status
)
}
}
if
!
strings
.
Contains
(
status
.
Message
,
"type apiserver.
T
is not registered"
)
{
if
!
strings
.
Contains
(
status
.
Message
,
"type apiserver.
UnregisteredAPIObject
is not registered"
)
{
t
.
Errorf
(
"unexpected message %#v"
,
status
)
t
.
Errorf
(
"unexpected message %#v"
,
status
)
}
}
}
}
...
@@ -705,7 +712,7 @@ func TestSyncCreateTimeout(t *testing.T) {
...
@@ -705,7 +712,7 @@ func TestSyncCreateTimeout(t *testing.T) {
testOver
:=
make
(
chan
struct
{})
testOver
:=
make
(
chan
struct
{})
defer
close
(
testOver
)
defer
close
(
testOver
)
storage
:=
SimpleRESTStorage
{
storage
:=
SimpleRESTStorage
{
injectedFunction
:
func
(
obj
interface
{})
(
interface
{}
,
error
)
{
injectedFunction
:
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
// Eliminate flakes by ensuring the create operation takes longer than this test.
// Eliminate flakes by ensuring the create operation takes longer than this test.
<-
testOver
<-
testOver
return
obj
,
nil
return
obj
,
nil
...
@@ -716,7 +723,7 @@ func TestSyncCreateTimeout(t *testing.T) {
...
@@ -716,7 +723,7 @@ func TestSyncCreateTimeout(t *testing.T) {
},
codec
,
"/prefix/version"
)
},
codec
,
"/prefix/version"
)
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
simple
:=
Simple
{
Name
:
"foo"
}
simple
:=
&
Simple
{
Name
:
"foo"
}
data
,
_
:=
codec
.
Encode
(
simple
)
data
,
_
:=
codec
.
Encode
(
simple
)
itemOut
:=
expectApiStatus
(
t
,
"POST"
,
server
.
URL
+
"/prefix/version/foo?sync=true&timeout=4ms"
,
data
,
http
.
StatusAccepted
)
itemOut
:=
expectApiStatus
(
t
,
"POST"
,
server
.
URL
+
"/prefix/version/foo?sync=true&timeout=4ms"
,
data
,
http
.
StatusAccepted
)
if
itemOut
.
Status
!=
api
.
StatusWorking
||
itemOut
.
Details
==
nil
||
itemOut
.
Details
.
ID
==
""
{
if
itemOut
.
Status
!=
api
.
StatusWorking
||
itemOut
.
Details
==
nil
||
itemOut
.
Details
.
ID
==
""
{
...
...
pkg/apiserver/operation_test.go
View file @
fc09f988
...
@@ -28,12 +28,13 @@ import (
...
@@ -28,12 +28,13 @@ import (
// TODO: remove dependency on api, apiserver should be generic
// TODO: remove dependency on api, apiserver should be generic
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
_
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
_
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
)
func
TestOperation
(
t
*
testing
.
T
)
{
func
TestOperation
(
t
*
testing
.
T
)
{
ops
:=
NewOperations
()
ops
:=
NewOperations
()
c
:=
make
(
chan
interface
{}
)
c
:=
make
(
chan
runtime
.
Object
)
op
:=
ops
.
NewOperation
(
c
)
op
:=
ops
.
NewOperation
(
c
)
// Allow context switch, so that op's ID can get added to the map and Get will work.
// Allow context switch, so that op's ID can get added to the map and Get will work.
// This is just so we can test Get. Ordinary users have no need to call Get immediately
// This is just so we can test Get. Ordinary users have no need to call Get immediately
...
@@ -41,7 +42,7 @@ func TestOperation(t *testing.T) {
...
@@ -41,7 +42,7 @@ func TestOperation(t *testing.T) {
time
.
Sleep
(
time
.
Millisecond
)
time
.
Sleep
(
time
.
Millisecond
)
go
func
()
{
go
func
()
{
time
.
Sleep
(
500
*
time
.
Millisecond
)
time
.
Sleep
(
500
*
time
.
Millisecond
)
c
<-
"All done"
c
<-
&
Simple
{
JSONBase
:
api
.
JSONBase
{
ID
:
"All done"
}}
}()
}()
if
op
.
expired
(
time
.
Now
()
.
Add
(
-
time
.
Minute
))
{
if
op
.
expired
(
time
.
Now
()
.
Add
(
-
time
.
Minute
))
{
...
@@ -89,7 +90,7 @@ func TestOperation(t *testing.T) {
...
@@ -89,7 +90,7 @@ func TestOperation(t *testing.T) {
t
.
Errorf
(
"expire failed to remove the operation %#v"
,
ops
)
t
.
Errorf
(
"expire failed to remove the operation %#v"
,
ops
)
}
}
if
op
.
result
.
(
string
)
!=
"All done"
{
if
op
.
result
.
(
*
Simple
)
.
ID
!=
"All done"
{
t
.
Errorf
(
"Got unexpected result: %#v"
,
op
.
result
)
t
.
Errorf
(
"Got unexpected result: %#v"
,
op
.
result
)
}
}
}
}
...
@@ -98,7 +99,7 @@ func TestOperationsList(t *testing.T) {
...
@@ -98,7 +99,7 @@ func TestOperationsList(t *testing.T) {
testOver
:=
make
(
chan
struct
{})
testOver
:=
make
(
chan
struct
{})
defer
close
(
testOver
)
defer
close
(
testOver
)
simpleStorage
:=
&
SimpleRESTStorage
{
simpleStorage
:=
&
SimpleRESTStorage
{
injectedFunction
:
func
(
obj
interface
{})
(
interface
{}
,
error
)
{
injectedFunction
:
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
// Eliminate flakes by ensuring the create operation takes longer than this test.
// Eliminate flakes by ensuring the create operation takes longer than this test.
<-
testOver
<-
testOver
return
obj
,
nil
return
obj
,
nil
...
@@ -111,7 +112,7 @@ func TestOperationsList(t *testing.T) {
...
@@ -111,7 +112,7 @@ func TestOperationsList(t *testing.T) {
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
client
:=
http
.
Client
{}
client
:=
http
.
Client
{}
simple
:=
Simple
{
simple
:=
&
Simple
{
Name
:
"foo"
,
Name
:
"foo"
,
}
}
data
,
err
:=
codec
.
Encode
(
simple
)
data
,
err
:=
codec
.
Encode
(
simple
)
...
@@ -154,7 +155,7 @@ func TestOpGet(t *testing.T) {
...
@@ -154,7 +155,7 @@ func TestOpGet(t *testing.T) {
testOver
:=
make
(
chan
struct
{})
testOver
:=
make
(
chan
struct
{})
defer
close
(
testOver
)
defer
close
(
testOver
)
simpleStorage
:=
&
SimpleRESTStorage
{
simpleStorage
:=
&
SimpleRESTStorage
{
injectedFunction
:
func
(
obj
interface
{})
(
interface
{}
,
error
)
{
injectedFunction
:
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
// Eliminate flakes by ensuring the create operation takes longer than this test.
// Eliminate flakes by ensuring the create operation takes longer than this test.
<-
testOver
<-
testOver
return
obj
,
nil
return
obj
,
nil
...
@@ -167,7 +168,7 @@ func TestOpGet(t *testing.T) {
...
@@ -167,7 +168,7 @@ func TestOpGet(t *testing.T) {
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
client
:=
http
.
Client
{}
client
:=
http
.
Client
{}
simple
:=
Simple
{
simple
:=
&
Simple
{
Name
:
"foo"
,
Name
:
"foo"
,
}
}
data
,
err
:=
codec
.
Encode
(
simple
)
data
,
err
:=
codec
.
Encode
(
simple
)
...
...
pkg/apiserver/watch_test.go
View file @
fc09f988
...
@@ -26,12 +26,13 @@ import (
...
@@ -26,12 +26,13 @@ import (
"code.google.com/p/go.net/websocket"
"code.google.com/p/go.net/websocket"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
)
var
watchTestTable
=
[]
struct
{
var
watchTestTable
=
[]
struct
{
t
watch
.
EventType
t
watch
.
EventType
obj
interface
{}
obj
runtime
.
Object
}{
}{
{
watch
.
Added
,
&
Simple
{
Name
:
"A Name"
}},
{
watch
.
Added
,
&
Simple
{
Name
:
"A Name"
}},
{
watch
.
Modified
,
&
Simple
{
Name
:
"Another Name"
}},
{
watch
.
Modified
,
&
Simple
{
Name
:
"Another Name"
}},
...
@@ -56,7 +57,7 @@ func TestWatchWebsocket(t *testing.T) {
...
@@ -56,7 +57,7 @@ func TestWatchWebsocket(t *testing.T) {
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
try
:=
func
(
action
watch
.
EventType
,
object
interface
{}
)
{
try
:=
func
(
action
watch
.
EventType
,
object
runtime
.
Object
)
{
// Send
// Send
simpleStorage
.
fakeWatch
.
Action
(
action
,
object
)
simpleStorage
.
fakeWatch
.
Action
(
action
,
object
)
// Test receive
// Test receive
...
@@ -113,7 +114,7 @@ func TestWatchHTTP(t *testing.T) {
...
@@ -113,7 +114,7 @@ func TestWatchHTTP(t *testing.T) {
decoder
:=
json
.
NewDecoder
(
response
.
Body
)
decoder
:=
json
.
NewDecoder
(
response
.
Body
)
try
:=
func
(
action
watch
.
EventType
,
object
interface
{}
)
{
try
:=
func
(
action
watch
.
EventType
,
object
runtime
.
Object
)
{
// Send
// Send
simpleStorage
.
fakeWatch
.
Action
(
action
,
object
)
simpleStorage
.
fakeWatch
.
Action
(
action
,
object
)
// Test receive
// Test receive
...
...
pkg/client/fake.go
View file @
fc09f988
...
@@ -129,7 +129,7 @@ func (c *Fake) WatchServices(label, field labels.Selector, resourceVersion uint6
...
@@ -129,7 +129,7 @@ func (c *Fake) WatchServices(label, field labels.Selector, resourceVersion uint6
func
(
c
*
Fake
)
ListEndpoints
(
selector
labels
.
Selector
)
(
*
api
.
EndpointsList
,
error
)
{
func
(
c
*
Fake
)
ListEndpoints
(
selector
labels
.
Selector
)
(
*
api
.
EndpointsList
,
error
)
{
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"list-endpoints"
})
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"list-endpoints"
})
return
runtime
.
DefaultScheme
.
CopyOrDie
(
&
c
.
EndpointsList
)
.
(
*
api
.
EndpointsList
),
nil
return
runtime
.
DefaultScheme
.
CopyOrDie
(
&
c
.
EndpointsList
)
.
(
*
api
.
EndpointsList
),
c
.
Err
}
}
func
(
c
*
Fake
)
WatchEndpoints
(
label
,
field
labels
.
Selector
,
resourceVersion
uint64
)
(
watch
.
Interface
,
error
)
{
func
(
c
*
Fake
)
WatchEndpoints
(
label
,
field
labels
.
Selector
,
resourceVersion
uint64
)
(
watch
.
Interface
,
error
)
{
...
...
pkg/controller/replication_controller_test.go
View file @
fc09f988
...
@@ -85,7 +85,7 @@ func newReplicationController(replicas int) api.ReplicationController {
...
@@ -85,7 +85,7 @@ func newReplicationController(replicas int) api.ReplicationController {
}
}
}
}
func
newPodList
(
count
int
)
api
.
PodList
{
func
newPodList
(
count
int
)
*
api
.
PodList
{
pods
:=
[]
api
.
Pod
{}
pods
:=
[]
api
.
Pod
{}
for
i
:=
0
;
i
<
count
;
i
++
{
for
i
:=
0
;
i
<
count
;
i
++
{
pods
=
append
(
pods
,
api
.
Pod
{
pods
=
append
(
pods
,
api
.
Pod
{
...
@@ -94,7 +94,7 @@ func newPodList(count int) api.PodList {
...
@@ -94,7 +94,7 @@ func newPodList(count int) api.PodList {
},
},
})
})
}
}
return
api
.
PodList
{
return
&
api
.
PodList
{
Items
:
pods
,
Items
:
pods
,
}
}
}
}
...
@@ -169,7 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
...
@@ -169,7 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
}
}
func
TestCreateReplica
(
t
*
testing
.
T
)
{
func
TestCreateReplica
(
t
*
testing
.
T
)
{
body
,
_
:=
runtime
.
DefaultCodec
.
Encode
(
api
.
Pod
{})
body
,
_
:=
runtime
.
DefaultCodec
.
Encode
(
&
api
.
Pod
{})
fakeHandler
:=
util
.
FakeHandler
{
fakeHandler
:=
util
.
FakeHandler
{
StatusCode
:
200
,
StatusCode
:
200
,
ResponseBody
:
string
(
body
),
ResponseBody
:
string
(
body
),
...
@@ -292,7 +292,7 @@ func TestSyncronize(t *testing.T) {
...
@@ -292,7 +292,7 @@ func TestSyncronize(t *testing.T) {
}
}
fakeControllerHandler
:=
util
.
FakeHandler
{
fakeControllerHandler
:=
util
.
FakeHandler
{
StatusCode
:
200
,
StatusCode
:
200
,
ResponseBody
:
runtime
.
EncodeOrDie
(
&
api
.
ReplicationControllerList
{
ResponseBody
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
ReplicationControllerList
{
Items
:
[]
api
.
ReplicationController
{
Items
:
[]
api
.
ReplicationController
{
controllerSpec1
,
controllerSpec1
,
controllerSpec2
,
controllerSpec2
,
...
...
pkg/election/etcd_master.go
View file @
fc09f988
...
@@ -27,6 +27,15 @@ import (
...
@@ -27,6 +27,15 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
)
)
// Master is used to announce the current elected master.
type
Master
string
// IsAnAPIObject is used solely so we can work with the watch package.
// TODO: Either fix watch so this isn't necessary, or make this a real API Object.
// TODO: when it becomes clear how this package will be used, move these declarations to
// to the proper place.
func
(
Master
)
IsAnAPIObject
()
{}
// NewEtcdMasterElector returns an implementation of election.MasterElector backed by etcd.
// NewEtcdMasterElector returns an implementation of election.MasterElector backed by etcd.
func
NewEtcdMasterElector
(
h
tools
.
EtcdGetSet
)
MasterElector
{
func
NewEtcdMasterElector
(
h
tools
.
EtcdGetSet
)
MasterElector
{
return
&
etcdMasterElector
{
etcd
:
h
}
return
&
etcdMasterElector
{
etcd
:
h
}
...
@@ -58,7 +67,7 @@ func (e *etcdMasterElector) run(path, id string) {
...
@@ -58,7 +67,7 @@ func (e *etcdMasterElector) run(path, id string) {
case
m
:=
<-
masters
:
case
m
:=
<-
masters
:
e
.
events
<-
watch
.
Event
{
e
.
events
<-
watch
.
Event
{
Type
:
watch
.
Modified
,
Type
:
watch
.
Modified
,
Object
:
m
,
Object
:
Master
(
m
)
,
}
}
case
e
:=
<-
errors
:
case
e
:=
<-
errors
:
glog
.
Errorf
(
"error in election: %v"
,
e
)
glog
.
Errorf
(
"error in election: %v"
,
e
)
...
...
pkg/election/etcd_master_test.go
View file @
fc09f988
...
@@ -31,7 +31,7 @@ func TestEtcdMasterOther(t *testing.T) {
...
@@ -31,7 +31,7 @@ func TestEtcdMasterOther(t *testing.T) {
master
:=
NewEtcdMasterElector
(
etcd
)
master
:=
NewEtcdMasterElector
(
etcd
)
w
:=
master
.
Elect
(
path
,
"bar"
)
w
:=
master
.
Elect
(
path
,
"bar"
)
result
:=
<-
w
.
ResultChan
()
result
:=
<-
w
.
ResultChan
()
if
result
.
Type
!=
watch
.
Modified
||
result
.
Object
.
(
string
)
!=
"baz"
{
if
result
.
Type
!=
watch
.
Modified
||
result
.
Object
.
(
Master
)
!=
"baz"
{
t
.
Errorf
(
"unexpected event: %#v"
,
result
)
t
.
Errorf
(
"unexpected event: %#v"
,
result
)
}
}
w
.
Stop
()
w
.
Stop
()
...
@@ -52,7 +52,7 @@ func TestEtcdMasterNoOther(t *testing.T) {
...
@@ -52,7 +52,7 @@ func TestEtcdMasterNoOther(t *testing.T) {
master
:=
NewEtcdMasterElector
(
e
)
master
:=
NewEtcdMasterElector
(
e
)
w
:=
master
.
Elect
(
path
,
"bar"
)
w
:=
master
.
Elect
(
path
,
"bar"
)
result
:=
<-
w
.
ResultChan
()
result
:=
<-
w
.
ResultChan
()
if
result
.
Type
!=
watch
.
Modified
||
result
.
Object
.
(
string
)
!=
"bar"
{
if
result
.
Type
!=
watch
.
Modified
||
result
.
Object
.
(
Master
)
!=
"bar"
{
t
.
Errorf
(
"unexpected event: %#v"
,
result
)
t
.
Errorf
(
"unexpected event: %#v"
,
result
)
}
}
w
.
Stop
()
w
.
Stop
()
...
@@ -91,7 +91,7 @@ func TestEtcdMasterNoOtherThenConflict(t *testing.T) {
...
@@ -91,7 +91,7 @@ func TestEtcdMasterNoOtherThenConflict(t *testing.T) {
master
:=
NewEtcdMasterElector
(
e
)
master
:=
NewEtcdMasterElector
(
e
)
w
:=
master
.
Elect
(
path
,
"bar"
)
w
:=
master
.
Elect
(
path
,
"bar"
)
result
:=
<-
w
.
ResultChan
()
result
:=
<-
w
.
ResultChan
()
if
result
.
Type
!=
watch
.
Modified
||
result
.
Object
.
(
string
)
!=
"bar"
{
if
result
.
Type
!=
watch
.
Modified
||
result
.
Object
.
(
Master
)
!=
"bar"
{
t
.
Errorf
(
"unexpected event: %#v"
,
result
)
t
.
Errorf
(
"unexpected event: %#v"
,
result
)
}
}
w
.
Stop
()
w
.
Stop
()
...
...
pkg/kubecfg/kubecfg_test.go
View file @
fc09f988
...
@@ -46,7 +46,7 @@ func TestUpdateWithPods(t *testing.T) {
...
@@ -46,7 +46,7 @@ func TestUpdateWithPods(t *testing.T) {
}
}
Update
(
"foo"
,
&
fakeClient
,
0
,
""
)
Update
(
"foo"
,
&
fakeClient
,
0
,
""
)
if
len
(
fakeClient
.
Actions
)
!=
5
{
if
len
(
fakeClient
.
Actions
)
!=
5
{
t
.
Error
f
(
"Unexpected action list %#v"
,
fakeClient
.
Actions
)
t
.
Fatal
f
(
"Unexpected action list %#v"
,
fakeClient
.
Actions
)
}
}
validateAction
(
client
.
FakeAction
{
Action
:
"get-controller"
,
Value
:
"foo"
},
fakeClient
.
Actions
[
0
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"get-controller"
,
Value
:
"foo"
},
fakeClient
.
Actions
[
0
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"list-pods"
},
fakeClient
.
Actions
[
1
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"list-pods"
},
fakeClient
.
Actions
[
1
],
t
)
...
@@ -94,7 +94,7 @@ func TestUpdateWithNewImage(t *testing.T) {
...
@@ -94,7 +94,7 @@ func TestUpdateWithNewImage(t *testing.T) {
}
}
validateAction
(
client
.
FakeAction
{
Action
:
"get-controller"
,
Value
:
"foo"
},
fakeClient
.
Actions
[
0
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"get-controller"
,
Value
:
"foo"
},
fakeClient
.
Actions
[
0
],
t
)
newCtrl
:=
*
runtime
.
CopyOrDie
(
fakeClient
.
Ctrl
)
.
(
*
api
.
ReplicationController
)
newCtrl
:=
runtime
.
DefaultScheme
.
CopyOrDie
(
&
fakeClient
.
Ctrl
)
.
(
*
api
.
ReplicationController
)
newCtrl
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
=
"fooImage:2"
newCtrl
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
=
"fooImage:2"
validateAction
(
client
.
FakeAction
{
Action
:
"update-controller"
,
Value
:
newCtrl
},
fakeClient
.
Actions
[
1
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"update-controller"
,
Value
:
newCtrl
},
fakeClient
.
Actions
[
1
],
t
)
...
@@ -114,7 +114,7 @@ func TestRunController(t *testing.T) {
...
@@ -114,7 +114,7 @@ func TestRunController(t *testing.T) {
if
len
(
fakeClient
.
Actions
)
!=
1
||
fakeClient
.
Actions
[
0
]
.
Action
!=
"create-controller"
{
if
len
(
fakeClient
.
Actions
)
!=
1
||
fakeClient
.
Actions
[
0
]
.
Action
!=
"create-controller"
{
t
.
Errorf
(
"Unexpected actions: %#v"
,
fakeClient
.
Actions
)
t
.
Errorf
(
"Unexpected actions: %#v"
,
fakeClient
.
Actions
)
}
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
ID
!=
name
||
if
controller
.
ID
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
...
@@ -133,7 +133,7 @@ func TestRunControllerWithService(t *testing.T) {
...
@@ -133,7 +133,7 @@ func TestRunControllerWithService(t *testing.T) {
fakeClient
.
Actions
[
1
]
.
Action
!=
"create-service"
{
fakeClient
.
Actions
[
1
]
.
Action
!=
"create-service"
{
t
.
Errorf
(
"Unexpected actions: %#v"
,
fakeClient
.
Actions
)
t
.
Errorf
(
"Unexpected actions: %#v"
,
fakeClient
.
Actions
)
}
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
ID
!=
name
||
if
controller
.
ID
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
...
@@ -152,7 +152,7 @@ func TestStopController(t *testing.T) {
...
@@ -152,7 +152,7 @@ func TestStopController(t *testing.T) {
fakeClient
.
Actions
[
0
]
.
Value
.
(
string
)
!=
name
{
fakeClient
.
Actions
[
0
]
.
Value
.
(
string
)
!=
name
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
0
])
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
0
])
}
}
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
controller
.
DesiredState
.
Replicas
!=
0
{
controller
.
DesiredState
.
Replicas
!=
0
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
...
@@ -171,7 +171,7 @@ func TestResizeController(t *testing.T) {
...
@@ -171,7 +171,7 @@ func TestResizeController(t *testing.T) {
fakeClient
.
Actions
[
0
]
.
Value
.
(
string
)
!=
name
{
fakeClient
.
Actions
[
0
]
.
Value
.
(
string
)
!=
name
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
0
])
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
0
])
}
}
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
controller
.
DesiredState
.
Replicas
!=
17
{
controller
.
DesiredState
.
Replicas
!=
17
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
...
...
pkg/kubecfg/parse.go
View file @
fc09f988
...
@@ -27,10 +27,11 @@ type Parser struct {
...
@@ -27,10 +27,11 @@ type Parser struct {
storageToType
map
[
string
]
reflect
.
Type
storageToType
map
[
string
]
reflect
.
Type
}
}
func
NewParser
(
objectMap
map
[
string
]
interface
{})
*
Parser
{
// NewParser creates a new parser.
func
NewParser
(
objectMap
map
[
string
]
runtime
.
Object
)
*
Parser
{
typeMap
:=
make
(
map
[
string
]
reflect
.
Type
)
typeMap
:=
make
(
map
[
string
]
reflect
.
Type
)
for
name
,
obj
:=
range
objectMap
{
for
name
,
obj
:=
range
objectMap
{
typeMap
[
name
]
=
reflect
.
TypeOf
(
obj
)
typeMap
[
name
]
=
reflect
.
TypeOf
(
obj
)
.
Elem
()
}
}
return
&
Parser
{
typeMap
}
return
&
Parser
{
typeMap
}
}
}
...
...
pkg/kubecfg/parse_test.go
View file @
fc09f988
...
@@ -25,14 +25,14 @@ import (
...
@@ -25,14 +25,14 @@ import (
)
)
func
TestParseBadStorage
(
t
*
testing
.
T
)
{
func
TestParseBadStorage
(
t
*
testing
.
T
)
{
p
:=
NewParser
(
map
[
string
]
interface
{}
{})
p
:=
NewParser
(
map
[
string
]
runtime
.
Object
{})
_
,
err
:=
p
.
ToWireFormat
([]
byte
(
"{}"
),
"badstorage"
)
_
,
err
:=
p
.
ToWireFormat
([]
byte
(
"{}"
),
"badstorage"
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"Expected error, received none"
)
t
.
Errorf
(
"Expected error, received none"
)
}
}
}
}
func
DoParseTest
(
t
*
testing
.
T
,
storage
string
,
obj
interface
{}
,
p
*
Parser
)
{
func
DoParseTest
(
t
*
testing
.
T
,
storage
string
,
obj
runtime
.
Object
,
p
*
Parser
)
{
jsonData
,
_
:=
runtime
.
DefaultCodec
.
Encode
(
obj
)
jsonData
,
_
:=
runtime
.
DefaultCodec
.
Encode
(
obj
)
yamlData
,
_
:=
yaml
.
Marshal
(
obj
)
yamlData
,
_
:=
yaml
.
Marshal
(
obj
)
t
.
Logf
(
"Intermediate yaml:
\n
%v
\n
"
,
string
(
yamlData
))
t
.
Logf
(
"Intermediate yaml:
\n
%v
\n
"
,
string
(
yamlData
))
...
@@ -56,14 +56,14 @@ func DoParseTest(t *testing.T, storage string, obj interface{}, p *Parser) {
...
@@ -56,14 +56,14 @@ func DoParseTest(t *testing.T, storage string, obj interface{}, p *Parser) {
}
}
}
}
var
testParser
=
NewParser
(
map
[
string
]
interface
{}
{
var
testParser
=
NewParser
(
map
[
string
]
runtime
.
Object
{
"pods"
:
api
.
Pod
{},
"pods"
:
&
api
.
Pod
{},
"services"
:
api
.
Service
{},
"services"
:
&
api
.
Service
{},
"replicationControllers"
:
api
.
ReplicationController
{},
"replicationControllers"
:
&
api
.
ReplicationController
{},
})
})
func
TestParsePod
(
t
*
testing
.
T
)
{
func
TestParsePod
(
t
*
testing
.
T
)
{
DoParseTest
(
t
,
"pods"
,
api
.
Pod
{
DoParseTest
(
t
,
"pods"
,
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
APIVersion
:
"v1beta1"
,
ID
:
"test pod"
,
Kind
:
"Pod"
},
JSONBase
:
api
.
JSONBase
{
APIVersion
:
"v1beta1"
,
ID
:
"test pod"
,
Kind
:
"Pod"
},
DesiredState
:
api
.
PodState
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Manifest
:
api
.
ContainerManifest
{
...
@@ -80,7 +80,7 @@ func TestParsePod(t *testing.T) {
...
@@ -80,7 +80,7 @@ func TestParsePod(t *testing.T) {
}
}
func
TestParseService
(
t
*
testing
.
T
)
{
func
TestParseService
(
t
*
testing
.
T
)
{
DoParseTest
(
t
,
"services"
,
api
.
Service
{
DoParseTest
(
t
,
"services"
,
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
APIVersion
:
"v1beta1"
,
ID
:
"my service"
,
Kind
:
"Service"
},
JSONBase
:
api
.
JSONBase
{
APIVersion
:
"v1beta1"
,
ID
:
"my service"
,
Kind
:
"Service"
},
Port
:
8080
,
Port
:
8080
,
Labels
:
map
[
string
]
string
{
Labels
:
map
[
string
]
string
{
...
@@ -93,7 +93,7 @@ func TestParseService(t *testing.T) {
...
@@ -93,7 +93,7 @@ func TestParseService(t *testing.T) {
}
}
func
TestParseController
(
t
*
testing
.
T
)
{
func
TestParseController
(
t
*
testing
.
T
)
{
DoParseTest
(
t
,
"replicationControllers"
,
api
.
ReplicationController
{
DoParseTest
(
t
,
"replicationControllers"
,
&
api
.
ReplicationController
{
JSONBase
:
api
.
JSONBase
{
APIVersion
:
"v1beta1"
,
ID
:
"my controller"
,
Kind
:
"ReplicationController"
},
JSONBase
:
api
.
JSONBase
{
APIVersion
:
"v1beta1"
,
ID
:
"my controller"
,
Kind
:
"ReplicationController"
},
DesiredState
:
api
.
ReplicationControllerState
{
DesiredState
:
api
.
ReplicationControllerState
{
Replicas
:
9001
,
Replicas
:
9001
,
...
@@ -119,13 +119,15 @@ type TestParseType struct {
...
@@ -119,13 +119,15 @@ type TestParseType struct {
Data
string
`json:"data" yaml:"data"`
Data
string
`json:"data" yaml:"data"`
}
}
func
(
*
TestParseType
)
IsAnAPIObject
()
{}
func
TestParseCustomType
(
t
*
testing
.
T
)
{
func
TestParseCustomType
(
t
*
testing
.
T
)
{
runtime
.
AddKnownTypes
(
""
,
TestParseType
{})
runtime
.
DefaultScheme
.
AddKnownTypes
(
""
,
&
TestParseType
{})
runtime
.
AddKnownTypes
(
"v1beta1"
,
TestParseType
{})
runtime
.
DefaultScheme
.
AddKnownTypes
(
"v1beta1"
,
&
TestParseType
{})
parser
:=
NewParser
(
map
[
string
]
interface
{}
{
parser
:=
NewParser
(
map
[
string
]
runtime
.
Object
{
"custom"
:
TestParseType
{},
"custom"
:
&
TestParseType
{},
})
})
DoParseTest
(
t
,
"custom"
,
TestParseType
{
DoParseTest
(
t
,
"custom"
,
&
TestParseType
{
JSONBase
:
api
.
JSONBase
{
APIVersion
:
""
,
ID
:
"my custom object"
,
Kind
:
"TestParseType"
},
JSONBase
:
api
.
JSONBase
{
APIVersion
:
""
,
ID
:
"my custom object"
,
Kind
:
"TestParseType"
},
Data
:
"test data"
,
Data
:
"test data"
,
},
parser
)
},
parser
)
...
...
pkg/kubecfg/resource_printer.go
View file @
fc09f988
...
@@ -62,7 +62,7 @@ type YAMLPrinter struct{}
...
@@ -62,7 +62,7 @@ type YAMLPrinter struct{}
// Print parses the data as JSON, re-formats as YAML and prints the YAML.
// Print parses the data as JSON, re-formats as YAML and prints the YAML.
func
(
y
*
YAMLPrinter
)
Print
(
data
[]
byte
,
w
io
.
Writer
)
error
{
func
(
y
*
YAMLPrinter
)
Print
(
data
[]
byte
,
w
io
.
Writer
)
error
{
var
obj
runtime
.
Object
var
obj
interface
{}
if
err
:=
json
.
Unmarshal
(
data
,
&
obj
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
data
,
&
obj
);
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubecfg/resource_printer_test.go
View file @
fc09f988
...
@@ -67,7 +67,7 @@ func TestYAMLPrinterPrint(t *testing.T) {
...
@@ -67,7 +67,7 @@ func TestYAMLPrinterPrint(t *testing.T) {
t
.
Errorf
(
"Test data and unmarshaled data are not equal: %#v vs %#v"
,
poutput
,
testData
)
t
.
Errorf
(
"Test data and unmarshaled data are not equal: %#v vs %#v"
,
poutput
,
testData
)
}
}
obj
:=
api
.
Pod
{
obj
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
}
}
buf
.
Reset
()
buf
.
Reset
()
...
@@ -77,8 +77,8 @@ func TestYAMLPrinterPrint(t *testing.T) {
...
@@ -77,8 +77,8 @@ func TestYAMLPrinterPrint(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpeted error: %#v"
,
err
)
t
.
Errorf
(
"Unexpeted error: %#v"
,
err
)
}
}
if
!
reflect
.
DeepEqual
(
obj
,
objOut
)
{
if
!
reflect
.
DeepEqual
(
obj
,
&
objOut
)
{
t
.
Errorf
(
"Unexpected inequality: %#v vs %#v"
,
obj
,
objOut
)
t
.
Errorf
(
"Unexpected inequality: %#v vs %#v"
,
obj
,
&
objOut
)
}
}
}
}
...
@@ -91,7 +91,7 @@ func TestIdentityPrinter(t *testing.T) {
...
@@ -91,7 +91,7 @@ func TestIdentityPrinter(t *testing.T) {
t
.
Errorf
(
"Bytes are not equal: %s vs %s"
,
str
,
buff
.
String
())
t
.
Errorf
(
"Bytes are not equal: %s vs %s"
,
str
,
buff
.
String
())
}
}
obj
:=
api
.
Pod
{
obj
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
}
}
buff
.
Reset
()
buff
.
Reset
()
...
@@ -100,7 +100,7 @@ func TestIdentityPrinter(t *testing.T) {
...
@@ -100,7 +100,7 @@ func TestIdentityPrinter(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpeted error: %#v"
,
err
)
t
.
Errorf
(
"Unexpeted error: %#v"
,
err
)
}
}
if
!
reflect
.
DeepEqual
(
&
obj
,
objOut
)
{
if
!
reflect
.
DeepEqual
(
obj
,
objOut
)
{
t
.
Errorf
(
"Unexpected inequality: %#v vs %#v"
,
obj
,
objOut
)
t
.
Errorf
(
"Unexpected inequality: %#v vs %#v"
,
obj
,
objOut
)
}
}
}
}
...
@@ -109,8 +109,12 @@ type TestPrintType struct {
...
@@ -109,8 +109,12 @@ type TestPrintType struct {
Data
string
Data
string
}
}
func
(
*
TestPrintType
)
IsAnAPIObject
()
{}
type
TestUnknownType
struct
{}
type
TestUnknownType
struct
{}
func
(
*
TestUnknownType
)
IsAnAPIObject
()
{}
func
PrintCustomType
(
obj
*
TestPrintType
,
w
io
.
Writer
)
error
{
func
PrintCustomType
(
obj
*
TestPrintType
,
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s"
,
obj
.
Data
)
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s"
,
obj
.
Data
)
return
err
return
err
...
...
pkg/registry/etcd/etcd_test.go
View file @
fc09f988
This diff is collapsed.
Click to expand it.
pkg/registry/minion/storage_test.go
View file @
fc09f988
...
@@ -28,10 +28,10 @@ func TestMinionRegistryStorage(t *testing.T) {
...
@@ -28,10 +28,10 @@ func TestMinionRegistryStorage(t *testing.T) {
m
:=
NewRegistry
([]
string
{
"foo"
,
"bar"
})
m
:=
NewRegistry
([]
string
{
"foo"
,
"bar"
})
ms
:=
NewRegistryStorage
(
m
)
ms
:=
NewRegistryStorage
(
m
)
if
obj
,
err
:=
ms
.
Get
(
"foo"
);
err
!=
nil
||
obj
.
(
api
.
Minion
)
.
ID
!=
"foo"
{
if
obj
,
err
:=
ms
.
Get
(
"foo"
);
err
!=
nil
||
obj
.
(
*
api
.
Minion
)
.
ID
!=
"foo"
{
t
.
Errorf
(
"missing expected object"
)
t
.
Errorf
(
"missing expected object"
)
}
}
if
obj
,
err
:=
ms
.
Get
(
"bar"
);
err
!=
nil
||
obj
.
(
api
.
Minion
)
.
ID
!=
"bar"
{
if
obj
,
err
:=
ms
.
Get
(
"bar"
);
err
!=
nil
||
obj
.
(
*
api
.
Minion
)
.
ID
!=
"bar"
{
t
.
Errorf
(
"missing expected object"
)
t
.
Errorf
(
"missing expected object"
)
}
}
if
_
,
err
:=
ms
.
Get
(
"baz"
);
err
!=
ErrDoesNotExist
{
if
_
,
err
:=
ms
.
Get
(
"baz"
);
err
!=
ErrDoesNotExist
{
...
@@ -43,10 +43,10 @@ func TestMinionRegistryStorage(t *testing.T) {
...
@@ -43,10 +43,10 @@ func TestMinionRegistryStorage(t *testing.T) {
t
.
Errorf
(
"insert failed"
)
t
.
Errorf
(
"insert failed"
)
}
}
obj
:=
<-
c
obj
:=
<-
c
if
m
,
ok
:=
obj
.
(
api
.
Minion
);
!
ok
||
m
.
ID
!=
"baz"
{
if
m
,
ok
:=
obj
.
(
*
api
.
Minion
);
!
ok
||
m
.
ID
!=
"baz"
{
t
.
Errorf
(
"insert return value was weird: %#v"
,
obj
)
t
.
Errorf
(
"insert return value was weird: %#v"
,
obj
)
}
}
if
obj
,
err
:=
ms
.
Get
(
"baz"
);
err
!=
nil
||
obj
.
(
api
.
Minion
)
.
ID
!=
"baz"
{
if
obj
,
err
:=
ms
.
Get
(
"baz"
);
err
!=
nil
||
obj
.
(
*
api
.
Minion
)
.
ID
!=
"baz"
{
t
.
Errorf
(
"insert didn't actually insert"
)
t
.
Errorf
(
"insert didn't actually insert"
)
}
}
...
@@ -78,7 +78,7 @@ func TestMinionRegistryStorage(t *testing.T) {
...
@@ -78,7 +78,7 @@ func TestMinionRegistryStorage(t *testing.T) {
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
},
},
}
}
if
!
reflect
.
DeepEqual
(
list
.
(
api
.
MinionList
)
.
Items
,
expect
)
{
if
!
reflect
.
DeepEqual
(
list
.
(
*
api
.
MinionList
)
.
Items
,
expect
)
{
t
.
Errorf
(
"Unexpected list value: %#v"
,
list
)
t
.
Errorf
(
"Unexpected list value: %#v"
,
list
)
}
}
}
}
pkg/registry/pod/storage_test.go
View file @
fc09f988
...
@@ -32,7 +32,7 @@ import (
...
@@ -32,7 +32,7 @@ import (
"github.com/fsouza/go-dockerclient"
"github.com/fsouza/go-dockerclient"
)
)
func
expectApiStatusError
(
t
*
testing
.
T
,
ch
<-
chan
interface
{}
,
msg
string
)
{
func
expectApiStatusError
(
t
*
testing
.
T
,
ch
<-
chan
runtime
.
Object
,
msg
string
)
{
out
:=
<-
ch
out
:=
<-
ch
status
,
ok
:=
out
.
(
*
api
.
Status
)
status
,
ok
:=
out
.
(
*
api
.
Status
)
if
!
ok
{
if
!
ok
{
...
@@ -44,7 +44,7 @@ func expectApiStatusError(t *testing.T, ch <-chan interface{}, msg string) {
...
@@ -44,7 +44,7 @@ func expectApiStatusError(t *testing.T, ch <-chan interface{}, msg string) {
}
}
}
}
func
expectPod
(
t
*
testing
.
T
,
ch
<-
chan
interface
{}
)
(
*
api
.
Pod
,
bool
)
{
func
expectPod
(
t
*
testing
.
T
,
ch
<-
chan
runtime
.
Object
)
(
*
api
.
Pod
,
bool
)
{
out
:=
<-
ch
out
:=
<-
ch
pod
,
ok
:=
out
.
(
*
api
.
Pod
)
pod
,
ok
:=
out
.
(
*
api
.
Pod
)
if
!
ok
||
pod
==
nil
{
if
!
ok
||
pod
==
nil
{
...
...
pkg/registry/registrytest/controller.go
View file @
fc09f988
...
@@ -35,11 +35,11 @@ func (r *ControllerRegistry) GetController(ID string) (*api.ReplicationControlle
...
@@ -35,11 +35,11 @@ func (r *ControllerRegistry) GetController(ID string) (*api.ReplicationControlle
return
&
api
.
ReplicationController
{},
r
.
Err
return
&
api
.
ReplicationController
{},
r
.
Err
}
}
func
(
r
*
ControllerRegistry
)
CreateController
(
controller
api
.
ReplicationController
)
error
{
func
(
r
*
ControllerRegistry
)
CreateController
(
controller
*
api
.
ReplicationController
)
error
{
return
r
.
Err
return
r
.
Err
}
}
func
(
r
*
ControllerRegistry
)
UpdateController
(
controller
api
.
ReplicationController
)
error
{
func
(
r
*
ControllerRegistry
)
UpdateController
(
controller
*
api
.
ReplicationController
)
error
{
return
r
.
Err
return
r
.
Err
}
}
...
...
pkg/registry/registrytest/pod.go
View file @
fc09f988
...
@@ -68,19 +68,19 @@ func (r *PodRegistry) GetPod(podId string) (*api.Pod, error) {
...
@@ -68,19 +68,19 @@ func (r *PodRegistry) GetPod(podId string) (*api.Pod, error) {
return
r
.
Pod
,
r
.
Err
return
r
.
Pod
,
r
.
Err
}
}
func
(
r
*
PodRegistry
)
CreatePod
(
pod
api
.
Pod
)
error
{
func
(
r
*
PodRegistry
)
CreatePod
(
pod
*
api
.
Pod
)
error
{
r
.
Lock
()
r
.
Lock
()
defer
r
.
Unlock
()
defer
r
.
Unlock
()
r
.
Pod
=
&
pod
r
.
Pod
=
pod
r
.
mux
.
Action
(
watch
.
Added
,
&
pod
)
r
.
mux
.
Action
(
watch
.
Added
,
pod
)
return
r
.
Err
return
r
.
Err
}
}
func
(
r
*
PodRegistry
)
UpdatePod
(
pod
api
.
Pod
)
error
{
func
(
r
*
PodRegistry
)
UpdatePod
(
pod
*
api
.
Pod
)
error
{
r
.
Lock
()
r
.
Lock
()
defer
r
.
Unlock
()
defer
r
.
Unlock
()
r
.
Pod
=
&
pod
r
.
Pod
=
pod
r
.
mux
.
Action
(
watch
.
Modified
,
&
pod
)
r
.
mux
.
Action
(
watch
.
Modified
,
pod
)
return
r
.
Err
return
r
.
Err
}
}
...
...
pkg/registry/registrytest/service.go
View file @
fc09f988
...
@@ -42,9 +42,9 @@ func (r *ServiceRegistry) ListServices() (*api.ServiceList, error) {
...
@@ -42,9 +42,9 @@ func (r *ServiceRegistry) ListServices() (*api.ServiceList, error) {
return
&
r
.
List
,
r
.
Err
return
&
r
.
List
,
r
.
Err
}
}
func
(
r
*
ServiceRegistry
)
CreateService
(
svc
api
.
Service
)
error
{
func
(
r
*
ServiceRegistry
)
CreateService
(
svc
*
api
.
Service
)
error
{
r
.
Service
=
&
svc
r
.
Service
=
svc
r
.
List
.
Items
=
append
(
r
.
List
.
Items
,
svc
)
r
.
List
.
Items
=
append
(
r
.
List
.
Items
,
*
svc
)
return
r
.
Err
return
r
.
Err
}
}
...
@@ -58,7 +58,7 @@ func (r *ServiceRegistry) DeleteService(id string) error {
...
@@ -58,7 +58,7 @@ func (r *ServiceRegistry) DeleteService(id string) error {
return
r
.
Err
return
r
.
Err
}
}
func
(
r
*
ServiceRegistry
)
UpdateService
(
svc
api
.
Service
)
error
{
func
(
r
*
ServiceRegistry
)
UpdateService
(
svc
*
api
.
Service
)
error
{
r
.
UpdatedID
=
svc
.
ID
r
.
UpdatedID
=
svc
.
ID
return
r
.
Err
return
r
.
Err
}
}
...
@@ -76,8 +76,8 @@ func (r *ServiceRegistry) GetEndpoints(id string) (*api.Endpoints, error) {
...
@@ -76,8 +76,8 @@ func (r *ServiceRegistry) GetEndpoints(id string) (*api.Endpoints, error) {
return
&
r
.
Endpoints
,
r
.
Err
return
&
r
.
Endpoints
,
r
.
Err
}
}
func
(
r
*
ServiceRegistry
)
UpdateEndpoints
(
e
api
.
Endpoints
)
error
{
func
(
r
*
ServiceRegistry
)
UpdateEndpoints
(
e
*
api
.
Endpoints
)
error
{
r
.
Endpoints
=
e
r
.
Endpoints
=
*
e
return
r
.
Err
return
r
.
Err
}
}
...
...
pkg/registry/service/storage_test.go
View file @
fc09f988
...
@@ -89,7 +89,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
...
@@ -89,7 +89,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
func
TestServiceRegistryUpdate
(
t
*
testing
.
T
)
{
func
TestServiceRegistryUpdate
(
t
*
testing
.
T
)
{
registry
:=
registrytest
.
NewServiceRegistry
()
registry
:=
registrytest
.
NewServiceRegistry
()
registry
.
CreateService
(
api
.
Service
{
registry
.
CreateService
(
&
api
.
Service
{
Port
:
6502
,
Port
:
6502
,
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz1"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz1"
},
...
@@ -118,7 +118,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
...
@@ -118,7 +118,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
func
TestServiceStorageValidatesUpdate
(
t
*
testing
.
T
)
{
func
TestServiceStorageValidatesUpdate
(
t
*
testing
.
T
)
{
registry
:=
registrytest
.
NewServiceRegistry
()
registry
:=
registrytest
.
NewServiceRegistry
()
registry
.
CreateService
(
api
.
Service
{
registry
.
CreateService
(
&
api
.
Service
{
Port
:
6502
,
Port
:
6502
,
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
...
@@ -200,7 +200,7 @@ func TestServiceRegistryDelete(t *testing.T) {
...
@@ -200,7 +200,7 @@ func TestServiceRegistryDelete(t *testing.T) {
fakeCloud
:=
&
cloud
.
FakeCloud
{}
fakeCloud
:=
&
cloud
.
FakeCloud
{}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
svc
:=
api
.
Service
{
svc
:=
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
}
}
...
@@ -220,7 +220,7 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
...
@@ -220,7 +220,7 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
fakeCloud
:=
&
cloud
.
FakeCloud
{}
fakeCloud
:=
&
cloud
.
FakeCloud
{}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
svc
:=
api
.
Service
{
svc
:=
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
CreateExternalLoadBalancer
:
true
,
CreateExternalLoadBalancer
:
true
,
...
@@ -263,7 +263,7 @@ func TestServiceRegistryGet(t *testing.T) {
...
@@ -263,7 +263,7 @@ func TestServiceRegistryGet(t *testing.T) {
fakeCloud
:=
&
cloud
.
FakeCloud
{}
fakeCloud
:=
&
cloud
.
FakeCloud
{}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
registry
.
CreateService
(
api
.
Service
{
registry
.
CreateService
(
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
})
})
...
@@ -282,7 +282,7 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
...
@@ -282,7 +282,7 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
fakeCloud
:=
&
cloud
.
FakeCloud
{}
fakeCloud
:=
&
cloud
.
FakeCloud
{}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
registry
.
CreateService
(
api
.
Service
{
registry
.
CreateService
(
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
})
})
...
@@ -310,11 +310,11 @@ func TestServiceRegistryList(t *testing.T) {
...
@@ -310,11 +310,11 @@ func TestServiceRegistryList(t *testing.T) {
fakeCloud
:=
&
cloud
.
FakeCloud
{}
fakeCloud
:=
&
cloud
.
FakeCloud
{}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
machines
:=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
storage
:=
NewRegistryStorage
(
registry
,
fakeCloud
,
minion
.
NewRegistry
(
machines
))
registry
.
CreateService
(
api
.
Service
{
registry
.
CreateService
(
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
})
})
registry
.
CreateService
(
api
.
Service
{
registry
.
CreateService
(
&
api
.
Service
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo2"
},
JSONBase
:
api
.
JSONBase
{
ID
:
"foo2"
},
Selector
:
map
[
string
]
string
{
"bar2"
:
"baz2"
},
Selector
:
map
[
string
]
string
{
"bar2"
:
"baz2"
},
})
})
...
...
pkg/tools/etcd_tools_test.go
View file @
fc09f988
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/go-etcd/etcd"
...
@@ -40,15 +39,16 @@ type TestResource struct {
...
@@ -40,15 +39,16 @@ type TestResource struct {
Value
int
`json:"value" yaml:"value,omitempty"`
Value
int
`json:"value" yaml:"value,omitempty"`
}
}
var
scheme
*
conversion
.
Scheme
func
(
*
TestResource
)
IsAnAPIObject
()
{}
var
scheme
*
runtime
.
Scheme
var
codec
=
runtime
.
DefaultCodec
var
codec
=
runtime
.
DefaultCodec
var
versioner
=
runtime
.
DefaultResourceVersioner
var
versioner
=
runtime
.
DefaultResourceVersioner
func
init
()
{
func
init
()
{
scheme
=
conversion
.
NewScheme
()
scheme
=
runtime
.
NewScheme
(
""
,
"v1beta1"
)
scheme
.
ExternalVersion
=
"v1beta1"
scheme
.
AddKnownTypes
(
""
,
&
TestResource
{})
scheme
.
AddKnownTypes
(
""
,
TestResource
{})
scheme
.
AddKnownTypes
(
"v1beta1"
,
&
TestResource
{})
scheme
.
AddKnownTypes
(
"v1beta1"
,
TestResource
{})
}
}
func
TestIsEtcdNotFound
(
t
*
testing
.
T
)
{
func
TestIsEtcdNotFound
(
t
*
testing
.
T
)
{
...
@@ -166,7 +166,7 @@ func TestExtractObjNotFoundErr(t *testing.T) {
...
@@ -166,7 +166,7 @@ func TestExtractObjNotFoundErr(t *testing.T) {
}
}
func
TestSetObj
(
t
*
testing
.
T
)
{
func
TestSetObj
(
t
*
testing
.
T
)
{
obj
:=
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
obj
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
EtcdHelper
{
fakeClient
,
codec
,
versioner
}
helper
:=
EtcdHelper
{
fakeClient
,
codec
,
versioner
}
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
)
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
)
...
@@ -191,7 +191,7 @@ func TestSetObjWithVersion(t *testing.T) {
...
@@ -191,7 +191,7 @@ func TestSetObjWithVersion(t *testing.T) {
fakeClient
.
Data
[
"/some/key"
]
=
EtcdResponseWithError
{
fakeClient
.
Data
[
"/some/key"
]
=
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
obj
),
Value
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
obj
),
ModifiedIndex
:
1
,
ModifiedIndex
:
1
,
},
},
},
},
...
@@ -214,7 +214,7 @@ func TestSetObjWithVersion(t *testing.T) {
...
@@ -214,7 +214,7 @@ func TestSetObjWithVersion(t *testing.T) {
}
}
func
TestSetObjWithoutResourceVersioner
(
t
*
testing
.
T
)
{
func
TestSetObjWithoutResourceVersioner
(
t
*
testing
.
T
)
{
obj
:=
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
obj
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
EtcdHelper
{
fakeClient
,
codec
,
nil
}
helper
:=
EtcdHelper
{
fakeClient
,
codec
,
nil
}
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
)
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
)
...
@@ -241,7 +241,7 @@ func TestAtomicUpdate(t *testing.T) {
...
@@ -241,7 +241,7 @@ func TestAtomicUpdate(t *testing.T) {
// Create a new node.
// Create a new node.
fakeClient
.
ExpectNotFoundGet
(
"/some/key"
)
fakeClient
.
ExpectNotFoundGet
(
"/some/key"
)
obj
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
1
}
obj
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
1
}
err
:=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
interface
{})
(
interface
{}
,
error
)
{
err
:=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
obj
,
nil
return
obj
,
nil
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -260,7 +260,7 @@ func TestAtomicUpdate(t *testing.T) {
...
@@ -260,7 +260,7 @@ func TestAtomicUpdate(t *testing.T) {
// Update an existing node.
// Update an existing node.
callbackCalled
:=
false
callbackCalled
:=
false
objUpdate
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
2
}
objUpdate
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
2
}
err
=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
interface
{})
(
interface
{}
,
error
)
{
err
=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
callbackCalled
=
true
callbackCalled
=
true
if
in
.
(
*
TestResource
)
.
Value
!=
1
{
if
in
.
(
*
TestResource
)
.
Value
!=
1
{
...
@@ -295,7 +295,7 @@ func TestAtomicUpdateNoChange(t *testing.T) {
...
@@ -295,7 +295,7 @@ func TestAtomicUpdateNoChange(t *testing.T) {
// Create a new node.
// Create a new node.
fakeClient
.
ExpectNotFoundGet
(
"/some/key"
)
fakeClient
.
ExpectNotFoundGet
(
"/some/key"
)
obj
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
1
}
obj
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
1
}
err
:=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
interface
{})
(
interface
{}
,
error
)
{
err
:=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
obj
,
nil
return
obj
,
nil
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -306,7 +306,7 @@ func TestAtomicUpdateNoChange(t *testing.T) {
...
@@ -306,7 +306,7 @@ func TestAtomicUpdateNoChange(t *testing.T) {
callbackCalled
:=
false
callbackCalled
:=
false
objUpdate
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
1
}
objUpdate
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
1
}
fakeClient
.
Err
=
errors
.
New
(
"should not be called"
)
fakeClient
.
Err
=
errors
.
New
(
"should not be called"
)
err
=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
interface
{})
(
interface
{}
,
error
)
{
err
=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
callbackCalled
=
true
callbackCalled
=
true
return
objUpdate
,
nil
return
objUpdate
,
nil
})
})
...
@@ -338,7 +338,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) {
...
@@ -338,7 +338,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) {
defer
wgDone
.
Done
()
defer
wgDone
.
Done
()
firstCall
:=
true
firstCall
:=
true
err
:=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
interface
{})
(
interface
{}
,
error
)
{
err
:=
helper
.
AtomicUpdate
(
"/some/key"
,
&
TestResource
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
defer
func
()
{
firstCall
=
false
}()
defer
func
()
{
firstCall
=
false
}()
if
firstCall
{
if
firstCall
{
...
@@ -348,7 +348,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) {
...
@@ -348,7 +348,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) {
}
}
currValue
:=
in
.
(
*
TestResource
)
.
Value
currValue
:=
in
.
(
*
TestResource
)
.
Value
obj
:=
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
currValue
+
1
}
obj
:=
&
TestResource
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Value
:
currValue
+
1
}
return
obj
,
nil
return
obj
,
nil
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/tools/etcd_tools_watch_test.go
View file @
fc09f988
...
@@ -33,7 +33,7 @@ func TestWatchInterpretations(t *testing.T) {
...
@@ -33,7 +33,7 @@ func TestWatchInterpretations(t *testing.T) {
podFoo
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
podFoo
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
podBar
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"bar"
}}
podBar
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"bar"
}}
podBaz
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"baz"
}}
podBaz
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"baz"
}}
firstLetterIsB
:=
func
(
obj
interface
{}
)
bool
{
firstLetterIsB
:=
func
(
obj
runtime
.
Object
)
bool
{
return
obj
.
(
*
api
.
Pod
)
.
ID
[
0
]
==
'b'
return
obj
.
(
*
api
.
Pod
)
.
ID
[
0
]
==
'b'
}
}
...
@@ -44,66 +44,66 @@ func TestWatchInterpretations(t *testing.T) {
...
@@ -44,66 +44,66 @@ func TestWatchInterpretations(t *testing.T) {
nodeValue
string
nodeValue
string
expectEmit
bool
expectEmit
bool
expectType
watch
.
EventType
expectType
watch
.
EventType
expectObject
interface
{}
expectObject
runtime
.
Object
}{
}{
"create"
:
{
"create"
:
{
actions
:
[]
string
{
"create"
,
"get"
},
actions
:
[]
string
{
"create"
,
"get"
},
nodeValue
:
runtime
.
EncodeOrDie
(
podBar
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podBar
),
expectEmit
:
true
,
expectEmit
:
true
,
expectType
:
watch
.
Added
,
expectType
:
watch
.
Added
,
expectObject
:
podBar
,
expectObject
:
podBar
,
},
},
"create but filter blocks"
:
{
"create but filter blocks"
:
{
actions
:
[]
string
{
"create"
,
"get"
},
actions
:
[]
string
{
"create"
,
"get"
},
nodeValue
:
runtime
.
EncodeOrDie
(
podFoo
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podFoo
),
expectEmit
:
false
,
expectEmit
:
false
,
},
},
"delete"
:
{
"delete"
:
{
actions
:
[]
string
{
"delete"
},
actions
:
[]
string
{
"delete"
},
prevNodeValue
:
runtime
.
EncodeOrDie
(
podBar
),
prevNodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podBar
),
expectEmit
:
true
,
expectEmit
:
true
,
expectType
:
watch
.
Deleted
,
expectType
:
watch
.
Deleted
,
expectObject
:
podBar
,
expectObject
:
podBar
,
},
},
"delete but filter blocks"
:
{
"delete but filter blocks"
:
{
actions
:
[]
string
{
"delete"
},
actions
:
[]
string
{
"delete"
},
nodeValue
:
runtime
.
EncodeOrDie
(
podFoo
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podFoo
),
expectEmit
:
false
,
expectEmit
:
false
,
},
},
"modify appears to create 1"
:
{
"modify appears to create 1"
:
{
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
nodeValue
:
runtime
.
EncodeOrDie
(
podBar
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podBar
),
expectEmit
:
true
,
expectEmit
:
true
,
expectType
:
watch
.
Added
,
expectType
:
watch
.
Added
,
expectObject
:
podBar
,
expectObject
:
podBar
,
},
},
"modify appears to create 2"
:
{
"modify appears to create 2"
:
{
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
prevNodeValue
:
runtime
.
EncodeOrDie
(
podFoo
),
prevNodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podFoo
),
nodeValue
:
runtime
.
EncodeOrDie
(
podBar
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podBar
),
expectEmit
:
true
,
expectEmit
:
true
,
expectType
:
watch
.
Added
,
expectType
:
watch
.
Added
,
expectObject
:
podBar
,
expectObject
:
podBar
,
},
},
"modify appears to delete"
:
{
"modify appears to delete"
:
{
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
prevNodeValue
:
runtime
.
EncodeOrDie
(
podBar
),
prevNodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podBar
),
nodeValue
:
runtime
.
EncodeOrDie
(
podFoo
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podFoo
),
expectEmit
:
true
,
expectEmit
:
true
,
expectType
:
watch
.
Deleted
,
expectType
:
watch
.
Deleted
,
expectObject
:
podBar
,
// Should return last state that passed the filter!
expectObject
:
podBar
,
// Should return last state that passed the filter!
},
},
"modify modifies"
:
{
"modify modifies"
:
{
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
prevNodeValue
:
runtime
.
EncodeOrDie
(
podBar
),
prevNodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podBar
),
nodeValue
:
runtime
.
EncodeOrDie
(
podBaz
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podBaz
),
expectEmit
:
true
,
expectEmit
:
true
,
expectType
:
watch
.
Modified
,
expectType
:
watch
.
Modified
,
expectObject
:
podBaz
,
expectObject
:
podBaz
,
},
},
"modify ignores"
:
{
"modify ignores"
:
{
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
actions
:
[]
string
{
"set"
,
"compareAndSwap"
},
nodeValue
:
runtime
.
EncodeOrDie
(
podFoo
),
nodeValue
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
podFoo
),
expectEmit
:
false
,
expectEmit
:
false
,
},
},
}
}
...
@@ -259,7 +259,7 @@ func TestWatchEtcdState(t *testing.T) {
...
@@ -259,7 +259,7 @@ func TestWatchEtcdState(t *testing.T) {
{
{
Action
:
"create"
,
Action
:
"create"
,
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
string
(
runtime
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
Value
:
string
(
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
},
},
},
},
},
},
...
@@ -273,12 +273,12 @@ func TestWatchEtcdState(t *testing.T) {
...
@@ -273,12 +273,12 @@ func TestWatchEtcdState(t *testing.T) {
{
{
Action
:
"compareAndSwap"
,
Action
:
"compareAndSwap"
,
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
string
(
runtime
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{
"127.0.0.1:9000"
}})),
Value
:
string
(
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{
"127.0.0.1:9000"
}})),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
2
,
ModifiedIndex
:
2
,
},
},
PrevNode
:
&
etcd
.
Node
{
PrevNode
:
&
etcd
.
Node
{
Value
:
string
(
runtime
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
Value
:
string
(
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
1
,
ModifiedIndex
:
1
,
},
},
...
@@ -295,7 +295,7 @@ func TestWatchEtcdState(t *testing.T) {
...
@@ -295,7 +295,7 @@ func TestWatchEtcdState(t *testing.T) {
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
Action
:
"get"
,
Action
:
"get"
,
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
string
(
runtime
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
Value
:
string
(
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
1
,
ModifiedIndex
:
1
,
},
},
...
@@ -308,12 +308,12 @@ func TestWatchEtcdState(t *testing.T) {
...
@@ -308,12 +308,12 @@ func TestWatchEtcdState(t *testing.T) {
{
{
Action
:
"compareAndSwap"
,
Action
:
"compareAndSwap"
,
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
string
(
runtime
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{
"127.0.0.1:9000"
}})),
Value
:
string
(
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{
"127.0.0.1:9000"
}})),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
2
,
ModifiedIndex
:
2
,
},
},
PrevNode
:
&
etcd
.
Node
{
PrevNode
:
&
etcd
.
Node
{
Value
:
string
(
runtime
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
Value
:
string
(
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
Endpoints
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
Endpoints
:
[]
string
{}})),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
1
,
ModifiedIndex
:
1
,
},
},
...
@@ -370,7 +370,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
...
@@ -370,7 +370,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
EtcdResponseWithError
{
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
pod
),
Value
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
pod
),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
1
,
ModifiedIndex
:
1
,
},
},
...
@@ -385,7 +385,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
...
@@ -385,7 +385,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
EtcdResponseWithError
{
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
pod
),
Value
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
pod
),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
2
,
ModifiedIndex
:
2
,
},
},
...
@@ -443,13 +443,13 @@ func TestWatchListFromZeroIndex(t *testing.T) {
...
@@ -443,13 +443,13 @@ func TestWatchListFromZeroIndex(t *testing.T) {
Dir
:
true
,
Dir
:
true
,
Nodes
:
etcd
.
Nodes
{
Nodes
:
etcd
.
Nodes
{
&
etcd
.
Node
{
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
pod
),
Value
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
pod
),
CreatedIndex
:
1
,
CreatedIndex
:
1
,
ModifiedIndex
:
1
,
ModifiedIndex
:
1
,
Nodes
:
etcd
.
Nodes
{},
Nodes
:
etcd
.
Nodes
{},
},
},
&
etcd
.
Node
{
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
pod
),
Value
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
pod
),
CreatedIndex
:
2
,
CreatedIndex
:
2
,
ModifiedIndex
:
2
,
ModifiedIndex
:
2
,
Nodes
:
etcd
.
Nodes
{},
Nodes
:
etcd
.
Nodes
{},
...
...
pkg/watch/filter.go
View file @
fc09f988
...
@@ -24,6 +24,11 @@ type FilterFunc func(in Event) (out Event, keep bool)
...
@@ -24,6 +24,11 @@ type FilterFunc func(in Event) (out Event, keep bool)
// Putting a filter on a watch, as an unavoidable side-effect due to the way
// Putting a filter on a watch, as an unavoidable side-effect due to the way
// go channels work, effectively causes the watch's event channel to have its
// go channels work, effectively causes the watch's event channel to have its
// queue length increased by one.
// queue length increased by one.
//
// WARNING: filter has a fatal flaw, in that it can't properly update the
// Type field (Add/Modified/Deleted) to reflect items beginning to pass the
// filter when they previously didn't.
//
func
Filter
(
w
Interface
,
f
FilterFunc
)
Interface
{
func
Filter
(
w
Interface
,
f
FilterFunc
)
Interface
{
fw
:=
&
filteredWatch
{
fw
:=
&
filteredWatch
{
incoming
:
w
,
incoming
:
w
,
...
...
pkg/watch/filter_test.go
View file @
fc09f988
...
@@ -23,16 +23,16 @@ import (
...
@@ -23,16 +23,16 @@ import (
func
TestFilter
(
t
*
testing
.
T
)
{
func
TestFilter
(
t
*
testing
.
T
)
{
table
:=
[]
Event
{
table
:=
[]
Event
{
{
Added
,
"foo"
},
{
Added
,
testType
(
"foo"
)
},
{
Added
,
"bar"
},
{
Added
,
testType
(
"bar"
)
},
{
Added
,
"baz"
},
{
Added
,
testType
(
"baz"
)
},
{
Added
,
"qux"
},
{
Added
,
testType
(
"qux"
)
},
{
Added
,
"zoo"
},
{
Added
,
testType
(
"zoo"
)
},
}
}
source
:=
NewFake
()
source
:=
NewFake
()
filtered
:=
Filter
(
source
,
func
(
e
Event
)
(
Event
,
bool
)
{
filtered
:=
Filter
(
source
,
func
(
e
Event
)
(
Event
,
bool
)
{
return
e
,
e
.
Object
.
(
string
)[
0
]
!=
'b'
return
e
,
e
.
Object
.
(
testType
)[
0
]
!=
'b'
})
})
go
func
()
{
go
func
()
{
...
@@ -48,7 +48,7 @@ func TestFilter(t *testing.T) {
...
@@ -48,7 +48,7 @@ func TestFilter(t *testing.T) {
if
!
ok
{
if
!
ok
{
break
break
}
}
got
=
append
(
got
,
event
.
Object
.
(
string
))
got
=
append
(
got
,
string
(
event
.
Object
.
(
testType
)
))
}
}
if
e
,
a
:=
[]
string
{
"foo"
,
"qux"
,
"zoo"
},
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
[]
string
{
"foo"
,
"qux"
,
"zoo"
},
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
...
@@ -59,11 +59,11 @@ func TestFilter(t *testing.T) {
...
@@ -59,11 +59,11 @@ func TestFilter(t *testing.T) {
func
TestFilterStop
(
t
*
testing
.
T
)
{
func
TestFilterStop
(
t
*
testing
.
T
)
{
source
:=
NewFake
()
source
:=
NewFake
()
filtered
:=
Filter
(
source
,
func
(
e
Event
)
(
Event
,
bool
)
{
filtered
:=
Filter
(
source
,
func
(
e
Event
)
(
Event
,
bool
)
{
return
e
,
e
.
Object
.
(
string
)[
0
]
!=
'b'
return
e
,
e
.
Object
.
(
testType
)[
0
]
!=
'b'
})
})
go
func
()
{
go
func
()
{
source
.
Add
(
"foo"
)
source
.
Add
(
testType
(
"foo"
)
)
filtered
.
Stop
()
filtered
.
Stop
()
}()
}()
...
@@ -73,7 +73,7 @@ func TestFilterStop(t *testing.T) {
...
@@ -73,7 +73,7 @@ func TestFilterStop(t *testing.T) {
if
!
ok
{
if
!
ok
{
break
break
}
}
got
=
append
(
got
,
event
.
Object
.
(
string
))
got
=
append
(
got
,
string
(
event
.
Object
.
(
testType
)
))
}
}
if
e
,
a
:=
[]
string
{
"foo"
},
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
[]
string
{
"foo"
},
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
...
...
pkg/watch/iowatcher_test.go
View file @
fc09f988
...
@@ -20,13 +20,15 @@ import (
...
@@ -20,13 +20,15 @@ import (
"io"
"io"
"reflect"
"reflect"
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
)
type
fakeDecoder
struct
{
type
fakeDecoder
struct
{
items
chan
Event
items
chan
Event
}
}
func
(
f
fakeDecoder
)
Decode
()
(
action
EventType
,
object
interface
{}
,
err
error
)
{
func
(
f
fakeDecoder
)
Decode
()
(
action
EventType
,
object
runtime
.
Object
,
err
error
)
{
item
,
open
:=
<-
f
.
items
item
,
open
:=
<-
f
.
items
if
!
open
{
if
!
open
{
return
action
,
nil
,
io
.
EOF
return
action
,
nil
,
io
.
EOF
...
@@ -40,7 +42,7 @@ func (f fakeDecoder) Close() {
...
@@ -40,7 +42,7 @@ func (f fakeDecoder) Close() {
func
TestStreamWatcher
(
t
*
testing
.
T
)
{
func
TestStreamWatcher
(
t
*
testing
.
T
)
{
table
:=
[]
Event
{
table
:=
[]
Event
{
{
Added
,
"foo"
},
{
Added
,
testType
(
"foo"
)
},
}
}
fd
:=
fakeDecoder
{
make
(
chan
Event
,
5
)}
fd
:=
fakeDecoder
{
make
(
chan
Event
,
5
)}
...
...
pkg/watch/watch_test.go
View file @
fc09f988
...
@@ -20,17 +20,21 @@ import (
...
@@ -20,17 +20,21 @@ import (
"testing"
"testing"
)
)
type
testType
string
func
(
testType
)
IsAnAPIObject
()
{}
func
TestFake
(
t
*
testing
.
T
)
{
func
TestFake
(
t
*
testing
.
T
)
{
f
:=
NewFake
()
f
:=
NewFake
()
table
:=
[]
struct
{
table
:=
[]
struct
{
t
EventType
t
EventType
s
string
s
testType
}{
}{
{
Added
,
"foo"
},
{
Added
,
testType
(
"foo"
)
},
{
Modified
,
"qux"
},
{
Modified
,
testType
(
"qux"
)
},
{
Modified
,
"bar"
},
{
Modified
,
testType
(
"bar"
)
},
{
Deleted
,
"bar"
},
{
Deleted
,
testType
(
"bar"
)
},
}
}
// Prove that f implements Interface by phrasing this as a function.
// Prove that f implements Interface by phrasing this as a function.
...
@@ -43,7 +47,7 @@ func TestFake(t *testing.T) {
...
@@ -43,7 +47,7 @@ func TestFake(t *testing.T) {
if
e
,
a
:=
expect
.
t
,
got
.
Type
;
e
!=
a
{
if
e
,
a
:=
expect
.
t
,
got
.
Type
;
e
!=
a
{
t
.
Fatalf
(
"Expected %v, got %v"
,
e
,
a
)
t
.
Fatalf
(
"Expected %v, got %v"
,
e
,
a
)
}
}
if
a
,
ok
:=
got
.
Object
.
(
string
);
!
ok
||
a
!=
expect
.
s
{
if
a
,
ok
:=
got
.
Object
.
(
testType
);
!
ok
||
a
!=
expect
.
s
{
t
.
Fatalf
(
"Expected %v, got %v"
,
expect
.
s
,
a
)
t
.
Fatalf
(
"Expected %v, got %v"
,
expect
.
s
,
a
)
}
}
}
}
...
@@ -54,10 +58,10 @@ func TestFake(t *testing.T) {
...
@@ -54,10 +58,10 @@ func TestFake(t *testing.T) {
}
}
sender
:=
func
()
{
sender
:=
func
()
{
f
.
Add
(
"foo"
)
f
.
Add
(
testType
(
"foo"
)
)
f
.
Action
(
Modified
,
"qux"
)
f
.
Action
(
Modified
,
testType
(
"qux"
)
)
f
.
Modify
(
"bar"
)
f
.
Modify
(
testType
(
"bar"
)
)
f
.
Delete
(
"bar"
)
f
.
Delete
(
testType
(
"bar"
)
)
f
.
Stop
()
f
.
Stop
()
}
}
...
...
plugin/pkg/scheduler/factory/factory_test.go
View file @
fc09f988
...
@@ -113,7 +113,7 @@ func TestPollMinions(t *testing.T) {
...
@@ -113,7 +113,7 @@ func TestPollMinions(t *testing.T) {
ml
:=
&
api
.
MinionList
{
Items
:
item
.
minions
}
ml
:=
&
api
.
MinionList
{
Items
:
item
.
minions
}
handler
:=
util
.
FakeHandler
{
handler
:=
util
.
FakeHandler
{
StatusCode
:
200
,
StatusCode
:
200
,
ResponseBody
:
runtime
.
EncodeOrDie
(
ml
),
ResponseBody
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
ml
),
T
:
t
,
T
:
t
,
}
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
...
@@ -140,7 +140,7 @@ func TestDefaultErrorFunc(t *testing.T) {
...
@@ -140,7 +140,7 @@ func TestDefaultErrorFunc(t *testing.T) {
testPod
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
testPod
:=
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}
handler
:=
util
.
FakeHandler
{
handler
:=
util
.
FakeHandler
{
StatusCode
:
200
,
StatusCode
:
200
,
ResponseBody
:
runtime
.
EncodeOrDie
(
testPod
),
ResponseBody
:
runtime
.
DefaultScheme
.
EncodeOrDie
(
testPod
),
T
:
t
,
T
:
t
,
}
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
...
@@ -259,7 +259,7 @@ func TestBind(t *testing.T) {
...
@@ -259,7 +259,7 @@ func TestBind(t *testing.T) {
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
continue
continue
}
}
expectedBody
:=
runtime
.
EncodeOrDie
(
item
.
binding
)
expectedBody
:=
runtime
.
DefaultScheme
.
EncodeOrDie
(
item
.
binding
)
handler
.
ValidateRequest
(
t
,
"/api/v1beta1/bindings"
,
"POST"
,
&
expectedBody
)
handler
.
ValidateRequest
(
t
,
"/api/v1beta1/bindings"
,
"POST"
,
&
expectedBody
)
}
}
}
}
test/integration/client_test.go
View file @
fc09f988
...
@@ -62,7 +62,7 @@ func TestClient(t *testing.T) {
...
@@ -62,7 +62,7 @@ func TestClient(t *testing.T) {
}
}
// get a validation error
// get a validation error
pod
:=
api
.
Pod
{
pod
:=
&
api
.
Pod
{
DesiredState
:
api
.
PodState
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Manifest
:
api
.
ContainerManifest
{
Version
:
"v1beta2"
,
Version
:
"v1beta2"
,
...
...
test/integration/etcd_tools_test.go
View file @
fc09f988
...
@@ -33,17 +33,22 @@ func init() {
...
@@ -33,17 +33,22 @@ func init() {
type
stringCodec
struct
{}
type
stringCodec
struct
{}
func
(
c
stringCodec
)
Encode
(
obj
interface
{})
([]
byte
,
error
)
{
type
fakeAPIObject
string
return
[]
byte
(
obj
.
(
string
)),
nil
func
(
*
fakeAPIObject
)
IsAnAPIObject
()
{}
func
(
c
stringCodec
)
Encode
(
obj
runtime
.
Object
)
([]
byte
,
error
)
{
return
[]
byte
(
*
obj
.
(
*
fakeAPIObject
)),
nil
}
}
func
(
c
stringCodec
)
Decode
(
data
[]
byte
)
(
interface
{},
error
)
{
func
(
c
stringCodec
)
Decode
(
data
[]
byte
)
(
runtime
.
Object
,
error
)
{
return
string
(
data
),
nil
o
:=
fakeAPIObject
(
data
)
return
&
o
,
nil
}
}
func
(
c
stringCodec
)
DecodeInto
(
data
[]
byte
,
obj
interface
{}
)
error
{
func
(
c
stringCodec
)
DecodeInto
(
data
[]
byte
,
obj
runtime
.
Object
)
error
{
o
:=
obj
.
(
*
string
)
o
:=
obj
.
(
*
fakeAPIObject
)
*
o
=
string
(
data
)
*
o
=
fakeAPIObject
(
data
)
return
nil
return
nil
}
}
...
@@ -51,7 +56,8 @@ func TestSetObj(t *testing.T) {
...
@@ -51,7 +56,8 @@ func TestSetObj(t *testing.T) {
client
:=
newEtcdClient
()
client
:=
newEtcdClient
()
helper
:=
tools
.
EtcdHelper
{
Client
:
client
,
Codec
:
stringCodec
{}}
helper
:=
tools
.
EtcdHelper
{
Client
:
client
,
Codec
:
stringCodec
{}}
withEtcdKey
(
func
(
key
string
)
{
withEtcdKey
(
func
(
key
string
)
{
if
err
:=
helper
.
SetObj
(
key
,
"object"
);
err
!=
nil
{
fakeObject
:=
fakeAPIObject
(
"object"
)
if
err
:=
helper
.
SetObj
(
key
,
&
fakeObject
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
resp
,
err
:=
client
.
Get
(
key
,
false
,
false
)
resp
,
err
:=
client
.
Get
(
key
,
false
,
false
)
...
@@ -72,7 +78,7 @@ func TestExtractObj(t *testing.T) {
...
@@ -72,7 +78,7 @@ func TestExtractObj(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
s
:=
""
s
:=
fakeAPIObject
(
""
)
if
err
:=
helper
.
ExtractObj
(
key
,
&
s
,
false
);
err
!=
nil
{
if
err
:=
helper
.
ExtractObj
(
key
,
&
s
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -86,7 +92,7 @@ func TestWatch(t *testing.T) {
...
@@ -86,7 +92,7 @@ func TestWatch(t *testing.T) {
client
:=
newEtcdClient
()
client
:=
newEtcdClient
()
helper
:=
tools
.
EtcdHelper
{
Client
:
client
,
Codec
:
runtime
.
DefaultCodec
,
ResourceVersioner
:
runtime
.
DefaultResourceVersioner
}
helper
:=
tools
.
EtcdHelper
{
Client
:
client
,
Codec
:
runtime
.
DefaultCodec
,
ResourceVersioner
:
runtime
.
DefaultResourceVersioner
}
withEtcdKey
(
func
(
key
string
)
{
withEtcdKey
(
func
(
key
string
)
{
resp
,
err
:=
client
.
Set
(
key
,
runtime
.
EncodeOrDie
(
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}),
0
)
resp
,
err
:=
client
.
Set
(
key
,
runtime
.
DefaultScheme
.
EncodeOrDie
(
&
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
}}),
0
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
...
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