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
7e3b7f96
Commit
7e3b7f96
authored
Mar 24, 2015
by
nikhiljindal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating unit tests so that they pass with v1beta3 api
parent
a4c02d8e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
155 deletions
+148
-155
testapi.go
pkg/api/testapi/testapi.go
+32
-0
listwatch_test.go
pkg/client/cache/listwatch_test.go
+20
-6
replication_controller_test.go
pkg/controller/replication_controller_test.go
+64
-107
helper_test.go
pkg/kubectl/resource/helper_test.go
+1
-1
endpoints_controller_test.go
pkg/service/endpoints_controller_test.go
+22
-19
factory_test.go
plugin/pkg/scheduler/factory/factory_test.go
+9
-22
No files found.
pkg/api/testapi/testapi.go
View file @
7e3b7f96
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"fmt"
"fmt"
"os"
"os"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
...
@@ -74,3 +75,34 @@ func SelfLink(resource, name string) string {
...
@@ -74,3 +75,34 @@ func SelfLink(resource, name string) string {
}
}
return
fmt
.
Sprintf
(
"/api/%s/%s/%s"
,
Version
(),
resource
,
name
)
return
fmt
.
Sprintf
(
"/api/%s/%s/%s"
,
Version
(),
resource
,
name
)
}
}
// Returns the appropriate path for the given resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/pods/pod0 for v1beta1 and
// /api/v1beta3/namespaces/foo/pods/pod0 for v1beta3.
func
ResourcePath
(
resource
,
namespace
,
name
string
)
string
{
path
:=
"/api/"
+
Version
()
if
!
api
.
PreV1Beta3
(
Version
())
&&
namespace
!=
""
{
path
=
path
+
"/namespaces/"
+
namespace
}
if
resource
!=
""
{
path
=
path
+
"/"
+
resource
}
if
name
!=
""
{
path
=
path
+
"/"
+
name
}
return
path
}
// Returns the appropriate path along with the query params for the given resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/pods/pod0?namespace=foo for v1beta1 and
// /api/v1beta3/namespaces/foo/pods/pod0 for v1beta3.
func
ResourcePathWithQueryParams
(
resource
,
namespace
,
name
string
)
string
{
path
:=
ResourcePath
(
resource
,
namespace
,
name
)
// Add namespace as query param for pre v1beta3.
if
api
.
PreV1Beta3
(
Version
())
{
path
=
path
+
"?namespace="
+
namespace
}
return
path
}
pkg/client/cache/listwatch_test.go
View file @
7e3b7f96
...
@@ -78,6 +78,7 @@ func buildLocation(resourcePath string, query url.Values) string {
...
@@ -78,6 +78,7 @@ func buildLocation(resourcePath string, query url.Values) string {
}
}
func
TestListWatchesCanList
(
t
*
testing
.
T
)
{
func
TestListWatchesCanList
(
t
*
testing
.
T
)
{
fieldSelectorQueryParamName
:=
api
.
FieldSelectorQueryParam
(
testapi
.
Version
())
table
:=
[]
struct
{
table
:=
[]
struct
{
location
string
location
string
resource
string
resource
string
...
@@ -93,14 +94,18 @@ func TestListWatchesCanList(t *testing.T) {
...
@@ -93,14 +94,18 @@ func TestListWatchesCanList(t *testing.T) {
},
},
// pod with "assigned" field selector.
// pod with "assigned" field selector.
{
{
location
:
buildLocation
(
buildResourcePath
(
""
,
api
.
NamespaceAll
,
"pods"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
"fields"
:
[]
string
{
getHostFieldLabel
()
+
"="
}})),
location
:
buildLocation
(
buildResourcePath
(
""
,
api
.
NamespaceAll
,
"pods"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
fieldSelectorQueryParamName
:
[]
string
{
getHostFieldLabel
()
+
"="
}})),
resource
:
"pods"
,
resource
:
"pods"
,
namespace
:
api
.
NamespaceAll
,
namespace
:
api
.
NamespaceAll
,
fieldSelector
:
fields
.
Set
{
getHostFieldLabel
()
:
""
}
.
AsSelector
(),
fieldSelector
:
fields
.
Set
{
getHostFieldLabel
()
:
""
}
.
AsSelector
(),
},
},
// pod in namespace "foo"
// pod in namespace "foo"
{
{
location
:
buildLocation
(
buildResourcePath
(
""
,
"foo"
,
"pods"
),
buildQueryValues
(
"foo"
,
url
.
Values
{
"fields"
:
[]
string
{
getHostFieldLabel
()
+
"="
}})),
location
:
buildLocation
(
buildResourcePath
(
""
,
"foo"
,
"pods"
),
buildQueryValues
(
"foo"
,
url
.
Values
{
fieldSelectorQueryParamName
:
[]
string
{
getHostFieldLabel
()
+
"="
}})),
resource
:
"pods"
,
resource
:
"pods"
,
namespace
:
"foo"
,
namespace
:
"foo"
,
fieldSelector
:
fields
.
Set
{
getHostFieldLabel
()
:
""
}
.
AsSelector
(),
fieldSelector
:
fields
.
Set
{
getHostFieldLabel
()
:
""
}
.
AsSelector
(),
...
@@ -123,6 +128,7 @@ func TestListWatchesCanList(t *testing.T) {
...
@@ -123,6 +128,7 @@ func TestListWatchesCanList(t *testing.T) {
}
}
func
TestListWatchesCanWatch
(
t
*
testing
.
T
)
{
func
TestListWatchesCanWatch
(
t
*
testing
.
T
)
{
fieldSelectorQueryParamName
:=
api
.
FieldSelectorQueryParam
(
testapi
.
Version
())
table
:=
[]
struct
{
table
:=
[]
struct
{
rv
string
rv
string
location
string
location
string
...
@@ -132,14 +138,18 @@ func TestListWatchesCanWatch(t *testing.T) {
...
@@ -132,14 +138,18 @@ func TestListWatchesCanWatch(t *testing.T) {
}{
}{
// Minion
// Minion
{
{
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
api
.
NamespaceAll
,
"minions"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
"resourceVersion"
:
[]
string
{
""
}})),
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
api
.
NamespaceAll
,
"minions"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
"resourceVersion"
:
[]
string
{
""
}})),
rv
:
""
,
rv
:
""
,
resource
:
"minions"
,
resource
:
"minions"
,
namespace
:
api
.
NamespaceAll
,
namespace
:
api
.
NamespaceAll
,
fieldSelector
:
parseSelectorOrDie
(
""
),
fieldSelector
:
parseSelectorOrDie
(
""
),
},
},
{
{
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
api
.
NamespaceAll
,
"minions"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
"resourceVersion"
:
[]
string
{
"42"
}})),
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
api
.
NamespaceAll
,
"minions"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
"resourceVersion"
:
[]
string
{
"42"
}})),
rv
:
"42"
,
rv
:
"42"
,
resource
:
"minions"
,
resource
:
"minions"
,
namespace
:
api
.
NamespaceAll
,
namespace
:
api
.
NamespaceAll
,
...
@@ -147,7 +157,9 @@ func TestListWatchesCanWatch(t *testing.T) {
...
@@ -147,7 +157,9 @@ func TestListWatchesCanWatch(t *testing.T) {
},
},
// pod with "assigned" field selector.
// pod with "assigned" field selector.
{
{
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
api
.
NamespaceAll
,
"pods"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
"fields"
:
[]
string
{
getHostFieldLabel
()
+
"="
},
"resourceVersion"
:
[]
string
{
"0"
}})),
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
api
.
NamespaceAll
,
"pods"
),
buildQueryValues
(
api
.
NamespaceAll
,
url
.
Values
{
fieldSelectorQueryParamName
:
[]
string
{
getHostFieldLabel
()
+
"="
},
"resourceVersion"
:
[]
string
{
"0"
}})),
rv
:
"0"
,
rv
:
"0"
,
resource
:
"pods"
,
resource
:
"pods"
,
namespace
:
api
.
NamespaceAll
,
namespace
:
api
.
NamespaceAll
,
...
@@ -155,7 +167,9 @@ func TestListWatchesCanWatch(t *testing.T) {
...
@@ -155,7 +167,9 @@ func TestListWatchesCanWatch(t *testing.T) {
},
},
// pod with namespace foo and assigned field selector
// pod with namespace foo and assigned field selector
{
{
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
"foo"
,
"pods"
),
buildQueryValues
(
"foo"
,
url
.
Values
{
"fields"
:
[]
string
{
getHostFieldLabel
()
+
"="
},
"resourceVersion"
:
[]
string
{
"0"
}})),
location
:
buildLocation
(
buildResourcePath
(
"watch"
,
"foo"
,
"pods"
),
buildQueryValues
(
"foo"
,
url
.
Values
{
fieldSelectorQueryParamName
:
[]
string
{
getHostFieldLabel
()
+
"="
},
"resourceVersion"
:
[]
string
{
"0"
}})),
rv
:
"0"
,
rv
:
"0"
,
resource
:
"pods"
,
resource
:
"pods"
,
namespace
:
"foo"
,
namespace
:
"foo"
,
...
...
pkg/controller/replication_controller_test.go
View file @
7e3b7f96
This diff is collapsed.
Click to expand it.
pkg/kubectl/resource/helper_test.go
View file @
7e3b7f96
...
@@ -329,7 +329,7 @@ func TestHelperList(t *testing.T) {
...
@@ -329,7 +329,7 @@ func TestHelperList(t *testing.T) {
t
.
Errorf
(
"url doesn't contain name: %#v"
,
req
.
URL
)
t
.
Errorf
(
"url doesn't contain name: %#v"
,
req
.
URL
)
return
false
return
false
}
}
if
req
.
URL
.
Query
()
.
Get
(
"labels"
)
!=
labels
.
SelectorFromSet
(
labels
.
Set
{
"foo"
:
"baz"
})
.
String
()
{
if
req
.
URL
.
Query
()
.
Get
(
api
.
LabelSelectorQueryParam
(
testapi
.
Version
())
)
!=
labels
.
SelectorFromSet
(
labels
.
Set
{
"foo"
:
"baz"
})
.
String
()
{
t
.
Errorf
(
"url doesn't contain query parameters: %#v"
,
req
.
URL
)
t
.
Errorf
(
"url doesn't contain query parameters: %#v"
,
req
.
URL
)
return
false
return
false
}
}
...
...
pkg/service/endpoints_controller_test.go
View file @
7e3b7f96
...
@@ -231,7 +231,7 @@ type serverResponse struct {
...
@@ -231,7 +231,7 @@ type serverResponse struct {
obj
interface
{}
obj
interface
{}
}
}
func
makeTestServer
(
t
*
testing
.
T
,
podResponse
serverResponse
,
serviceResponse
server
Response
,
endpointsResponse
serverResponse
)
(
*
httptest
.
Server
,
*
util
.
FakeHandler
)
{
func
makeTestServer
(
t
*
testing
.
T
,
namespace
string
,
podResponse
,
service
Response
,
endpointsResponse
serverResponse
)
(
*
httptest
.
Server
,
*
util
.
FakeHandler
)
{
fakePodHandler
:=
util
.
FakeHandler
{
fakePodHandler
:=
util
.
FakeHandler
{
StatusCode
:
podResponse
.
statusCode
,
StatusCode
:
podResponse
.
statusCode
,
ResponseBody
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
podResponse
.
obj
.
(
runtime
.
Object
)),
ResponseBody
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
podResponse
.
obj
.
(
runtime
.
Object
)),
...
@@ -245,10 +245,10 @@ func makeTestServer(t *testing.T, podResponse serverResponse, serviceResponse se
...
@@ -245,10 +245,10 @@ func makeTestServer(t *testing.T, podResponse serverResponse, serviceResponse se
ResponseBody
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
endpointsResponse
.
obj
.
(
runtime
.
Object
)),
ResponseBody
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
endpointsResponse
.
obj
.
(
runtime
.
Object
)),
}
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
Handle
(
"/api/"
+
testapi
.
Version
()
+
"/pods"
,
&
fakePodHandler
)
mux
.
Handle
(
testapi
.
ResourcePath
(
"pods"
,
namespace
,
""
)
,
&
fakePodHandler
)
mux
.
Handle
(
"/api/"
+
testapi
.
Version
()
+
"/services"
,
&
fakeServiceHandler
)
mux
.
Handle
(
testapi
.
ResourcePath
(
"services"
,
""
,
""
)
,
&
fakeServiceHandler
)
mux
.
Handle
(
"/api/"
+
testapi
.
Version
()
+
"/endpoints"
,
&
fakeEndpointsHandler
)
mux
.
Handle
(
testapi
.
ResourcePath
(
"endpoints"
,
namespace
,
""
)
,
&
fakeEndpointsHandler
)
mux
.
Handle
(
"/api/"
+
testapi
.
Version
()
+
"/endpoints/"
,
&
fakeEndpointsHandler
)
mux
.
Handle
(
testapi
.
ResourcePath
(
"endpoints/"
,
namespace
,
""
)
,
&
fakeEndpointsHandler
)
mux
.
HandleFunc
(
"/"
,
func
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
mux
.
HandleFunc
(
"/"
,
func
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
t
.
Errorf
(
"unexpected request: %v"
,
req
.
RequestURI
)
t
.
Errorf
(
"unexpected request: %v"
,
req
.
RequestURI
)
res
.
WriteHeader
(
http
.
StatusNotFound
)
res
.
WriteHeader
(
http
.
StatusNotFound
)
...
@@ -257,7 +257,7 @@ func makeTestServer(t *testing.T, podResponse serverResponse, serviceResponse se
...
@@ -257,7 +257,7 @@ func makeTestServer(t *testing.T, podResponse serverResponse, serviceResponse se
}
}
func
TestSyncEndpointsEmpty
(
t
*
testing
.
T
)
{
func
TestSyncEndpointsEmpty
(
t
*
testing
.
T
)
{
testServer
,
_
:=
makeTestServer
(
t
,
testServer
,
_
:=
makeTestServer
(
t
,
api
.
NamespaceDefault
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
&
api
.
ServiceList
{}},
serverResponse
{
http
.
StatusOK
,
&
api
.
ServiceList
{}},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
...
@@ -270,7 +270,7 @@ func TestSyncEndpointsEmpty(t *testing.T) {
...
@@ -270,7 +270,7 @@ func TestSyncEndpointsEmpty(t *testing.T) {
}
}
func
TestSyncEndpointsError
(
t
*
testing
.
T
)
{
func
TestSyncEndpointsError
(
t
*
testing
.
T
)
{
testServer
,
_
:=
makeTestServer
(
t
,
testServer
,
_
:=
makeTestServer
(
t
,
api
.
NamespaceDefault
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusInternalServerError
,
&
api
.
ServiceList
{}},
serverResponse
{
http
.
StatusInternalServerError
,
&
api
.
ServiceList
{}},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
...
@@ -291,7 +291,7 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
...
@@ -291,7 +291,7 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
},
},
},
},
}
}
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
api
.
NamespaceDefault
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
...
@@ -323,7 +323,7 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
...
@@ -323,7 +323,7 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
},
},
},
},
}
}
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
"other"
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
...
@@ -355,7 +355,7 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
...
@@ -355,7 +355,7 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
},
},
},
},
}
}
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
"other"
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
0
)},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
...
@@ -386,7 +386,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
...
@@ -386,7 +386,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
},
},
},
},
}
}
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
"other"
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
...
@@ -418,7 +418,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
...
@@ -418,7 +418,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
},
},
}},
}},
})
})
endpointsHandler
.
ValidateRequest
(
t
,
"/api/"
+
testapi
.
Version
()
+
"/endpoints/foo?namespace=other"
,
"PUT"
,
&
data
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePathWithQueryParams
(
"endpoints"
,
"other"
,
"foo"
)
,
"PUT"
,
&
data
)
}
}
func
TestSyncEndpointsItemsPreexisting
(
t
*
testing
.
T
)
{
func
TestSyncEndpointsItemsPreexisting
(
t
*
testing
.
T
)
{
...
@@ -434,7 +434,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
...
@@ -434,7 +434,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
},
},
},
},
}
}
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
"bar"
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
...
@@ -466,7 +466,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
...
@@ -466,7 +466,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
},
},
}},
}},
})
})
endpointsHandler
.
ValidateRequest
(
t
,
"/api/"
+
testapi
.
Version
()
+
"/endpoints/foo?namespace=bar"
,
"PUT"
,
&
data
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePathWithQueryParams
(
"endpoints"
,
"bar"
,
"foo"
)
,
"PUT"
,
&
data
)
}
}
func
TestSyncEndpointsItemsPreexistingIdentical
(
t
*
testing
.
T
)
{
func
TestSyncEndpointsItemsPreexistingIdentical
(
t
*
testing
.
T
)
{
...
@@ -482,7 +482,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
...
@@ -482,7 +482,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
},
},
},
},
}
}
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
api
.
NamespaceDefault
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{
...
@@ -505,7 +505,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
...
@@ -505,7 +505,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
if
err
:=
endpoints
.
SyncServiceEndpoints
();
err
!=
nil
{
if
err
:=
endpoints
.
SyncServiceEndpoints
();
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
endpointsHandler
.
ValidateRequest
(
t
,
"/api/"
+
testapi
.
Version
()
+
"/endpoints/foo?namespace=default"
,
"GET"
,
nil
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePathWithQueryParams
(
"endpoints"
,
api
.
NamespaceDefault
,
"foo"
)
,
"GET"
,
nil
)
}
}
func
TestSyncEndpointsItems
(
t
*
testing
.
T
)
{
func
TestSyncEndpointsItems
(
t
*
testing
.
T
)
{
...
@@ -521,7 +521,7 @@ func TestSyncEndpointsItems(t *testing.T) {
...
@@ -521,7 +521,7 @@ func TestSyncEndpointsItems(t *testing.T) {
},
},
},
},
}
}
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
"other"
,
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
newPodList
(
1
)},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
...
@@ -545,13 +545,16 @@ func TestSyncEndpointsItems(t *testing.T) {
...
@@ -545,13 +545,16 @@ func TestSyncEndpointsItems(t *testing.T) {
},
},
}},
}},
})
})
endpointsHandler
.
ValidateRequest
(
t
,
"/api/"
+
testapi
.
Version
()
+
"/endpoints?namespace=other"
,
"POST"
,
&
data
)
// endpointsHandler should get 2 requests - one for "GET" and the next for "POST".
endpointsHandler
.
ValidateRequestCount
(
t
,
2
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePathWithQueryParams
(
"endpoints"
,
"other"
,
""
),
"POST"
,
&
data
)
}
}
func
TestSyncEndpointsPodError
(
t
*
testing
.
T
)
{
func
TestSyncEndpointsPodError
(
t
*
testing
.
T
)
{
serviceList
:=
api
.
ServiceList
{
serviceList
:=
api
.
ServiceList
{
Items
:
[]
api
.
Service
{
Items
:
[]
api
.
Service
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
api
.
NamespaceDefault
},
Spec
:
api
.
ServiceSpec
{
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
,
"foo"
:
"bar"
,
...
@@ -560,7 +563,7 @@ func TestSyncEndpointsPodError(t *testing.T) {
...
@@ -560,7 +563,7 @@ func TestSyncEndpointsPodError(t *testing.T) {
},
},
},
},
}
}
testServer
,
_
:=
makeTestServer
(
t
,
testServer
,
_
:=
makeTestServer
(
t
,
api
.
NamespaceDefault
,
serverResponse
{
http
.
StatusInternalServerError
,
&
api
.
PodList
{}},
serverResponse
{
http
.
StatusInternalServerError
,
&
api
.
PodList
{}},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
serviceList
},
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
serverResponse
{
http
.
StatusOK
,
&
api
.
Endpoints
{}})
...
...
plugin/pkg/scheduler/factory/factory_test.go
View file @
7e3b7f96
...
@@ -19,7 +19,6 @@ package factory
...
@@ -19,7 +19,6 @@ package factory
import
(
import
(
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"path"
"reflect"
"reflect"
"testing"
"testing"
"time"
"time"
...
@@ -313,7 +312,11 @@ func TestPollMinions(t *testing.T) {
...
@@ -313,7 +312,11 @@ func TestPollMinions(t *testing.T) {
}
}
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
// FakeHandler musn't be sent requests other than the one you want to test.
// FakeHandler musn't be sent requests other than the one you want to test.
mux
.
Handle
(
"/api/"
+
testapi
.
Version
()
+
"/minions"
,
&
handler
)
resource
:=
"nodes"
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
resource
=
"minions"
}
mux
.
Handle
(
testapi
.
ResourcePath
(
resource
,
api
.
NamespaceAll
,
""
),
&
handler
)
server
:=
httptest
.
NewServer
(
mux
)
server
:=
httptest
.
NewServer
(
mux
)
defer
server
.
Close
()
defer
server
.
Close
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
server
.
URL
,
Version
:
testapi
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
server
.
URL
,
Version
:
testapi
.
Version
()})
...
@@ -324,7 +327,7 @@ func TestPollMinions(t *testing.T) {
...
@@ -324,7 +327,7 @@ func TestPollMinions(t *testing.T) {
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
continue
continue
}
}
handler
.
ValidateRequest
(
t
,
"/api/"
+
testapi
.
Version
()
+
"/minions"
,
"GET"
,
nil
)
handler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
resource
,
api
.
NamespaceAll
,
""
)
,
"GET"
,
nil
)
if
a
:=
ce
.
Len
();
item
.
expectedCount
!=
a
{
if
a
:=
ce
.
Len
();
item
.
expectedCount
!=
a
{
t
.
Errorf
(
"Expected %v, got %v"
,
item
.
expectedCount
,
a
)
t
.
Errorf
(
"Expected %v, got %v"
,
item
.
expectedCount
,
a
)
...
@@ -332,22 +335,6 @@ func TestPollMinions(t *testing.T) {
...
@@ -332,22 +335,6 @@ func TestPollMinions(t *testing.T) {
}
}
}
}
func
makeNamespaceURL
(
namespace
,
suffix
string
,
isClient
bool
)
string
{
if
!
(
testapi
.
Version
()
==
"v1beta1"
||
testapi
.
Version
()
==
"v1beta2"
)
{
return
makeURL
(
"/namespaces/"
+
namespace
+
suffix
)
}
// if this is a url the client should call, encode the url
if
isClient
{
return
makeURL
(
suffix
+
"?namespace="
+
namespace
)
}
// its not a client url, so its what the server needs to listen on
return
makeURL
(
suffix
)
}
func
makeURL
(
suffix
string
)
string
{
return
path
.
Join
(
"/api"
,
testapi
.
Version
(),
suffix
)
}
func
TestDefaultErrorFunc
(
t
*
testing
.
T
)
{
func
TestDefaultErrorFunc
(
t
*
testing
.
T
)
{
testPod
:=
&
api
.
Pod
{
testPod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"bar"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"bar"
},
...
@@ -364,7 +351,7 @@ func TestDefaultErrorFunc(t *testing.T) {
...
@@ -364,7 +351,7 @@ func TestDefaultErrorFunc(t *testing.T) {
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
// FakeHandler musn't be sent requests other than the one you want to test.
// FakeHandler musn't be sent requests other than the one you want to test.
mux
.
Handle
(
makeNamespaceURL
(
"bar"
,
"/pods/foo"
,
false
),
&
handler
)
mux
.
Handle
(
testapi
.
ResourcePath
(
"pods"
,
"bar"
,
"foo"
),
&
handler
)
server
:=
httptest
.
NewServer
(
mux
)
server
:=
httptest
.
NewServer
(
mux
)
defer
server
.
Close
()
defer
server
.
Close
()
factory
:=
NewConfigFactory
(
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
server
.
URL
,
Version
:
testapi
.
Version
()}))
factory
:=
NewConfigFactory
(
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
server
.
URL
,
Version
:
testapi
.
Version
()}))
...
@@ -387,7 +374,7 @@ func TestDefaultErrorFunc(t *testing.T) {
...
@@ -387,7 +374,7 @@ func TestDefaultErrorFunc(t *testing.T) {
if
!
exists
{
if
!
exists
{
continue
continue
}
}
handler
.
ValidateRequest
(
t
,
makeNamespaceURL
(
"bar"
,
"/pods/foo"
,
true
),
"GET"
,
nil
)
handler
.
ValidateRequest
(
t
,
testapi
.
ResourcePathWithQueryParams
(
"pods"
,
"bar"
,
"foo"
),
"GET"
,
nil
)
if
e
,
a
:=
testPod
,
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
testPod
,
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
}
}
...
@@ -458,7 +445,7 @@ func TestBind(t *testing.T) {
...
@@ -458,7 +445,7 @@ func TestBind(t *testing.T) {
continue
continue
}
}
expectedBody
:=
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
item
.
binding
)
expectedBody
:=
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
item
.
binding
)
handler
.
ValidateRequest
(
t
,
"/api/"
+
testapi
.
Version
()
+
"/bindings?namespace=default"
,
"POST"
,
&
expectedBody
)
handler
.
ValidateRequest
(
t
,
testapi
.
ResourcePathWithQueryParams
(
"bindings"
,
api
.
NamespaceDefault
,
""
)
,
"POST"
,
&
expectedBody
)
}
}
}
}
...
...
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