本文整理汇总了Golang中k8s/io/kubernetes/pkg/api/testapi.ResourcePath函数的典型用法代码示例。如果您正苦于以下问题:Golang ResourcePath函数的具体用法?Golang ResourcePath怎么用?Golang ResourcePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ResourcePath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: makeTestServer
func makeTestServer(t *testing.T, namespace, name string, podResponse, controllerResponse, updateResponse serverResponse) (*httptest.Server, *util.FakeHandler) {
fakePodHandler := util.FakeHandler{
StatusCode: podResponse.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), podResponse.obj.(runtime.Object)),
}
fakeControllerHandler := util.FakeHandler{
StatusCode: controllerResponse.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), controllerResponse.obj.(runtime.Object)),
}
fakeUpdateHandler := util.FakeHandler{
StatusCode: updateResponse.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), updateResponse.obj.(runtime.Object)),
}
mux := http.NewServeMux()
mux.Handle(testapi.ResourcePath("pods", namespace, ""), &fakePodHandler)
mux.Handle(testapi.ResourcePath(replicationControllerResourceName(), "", ""), &fakeControllerHandler)
if namespace != "" {
mux.Handle(testapi.ResourcePath(replicationControllerResourceName(), namespace, ""), &fakeControllerHandler)
}
if name != "" {
mux.Handle(testapi.ResourcePath(replicationControllerResourceName(), namespace, name), &fakeUpdateHandler)
}
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
t.Errorf("unexpected request: %v", req.RequestURI)
res.WriteHeader(http.StatusNotFound)
})
return httptest.NewServer(mux), &fakeUpdateHandler
}
开发者ID:Jandersolutions,项目名称:kubernetes,代码行数:28,代码来源:replication_controller_test.go
示例2: makeTestServer
func makeTestServer(t *testing.T, namespace string, endpointsResponse serverResponse) (*httptest.Server, *util.FakeHandler) {
fakeEndpointsHandler := util.FakeHandler{
StatusCode: endpointsResponse.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), endpointsResponse.obj.(runtime.Object)),
}
mux := http.NewServeMux()
mux.Handle(testapi.ResourcePath("endpoints", namespace, ""), &fakeEndpointsHandler)
mux.Handle(testapi.ResourcePath("endpoints/", namespace, ""), &fakeEndpointsHandler)
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
t.Errorf("unexpected request: %v", req.RequestURI)
res.WriteHeader(http.StatusNotFound)
})
return httptest.NewServer(mux), &fakeEndpointsHandler
}
开发者ID:Tlacenka,项目名称:origin,代码行数:14,代码来源:endpoints_controller_test.go
示例3: TestListWatchesCanList
func TestListWatchesCanList(t *testing.T) {
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Version())
table := []struct {
location string
resource string
namespace string
fieldSelector fields.Selector
}{
// Minion
{
location: testapi.ResourcePath("minions", api.NamespaceAll, ""),
resource: "minions",
namespace: api.NamespaceAll,
fieldSelector: parseSelectorOrDie(""),
},
// pod with "assigned" field selector.
{
location: buildLocation(
testapi.ResourcePath("pods", api.NamespaceAll, ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
resource: "pods",
namespace: api.NamespaceAll,
fieldSelector: fields.Set{"spec.host": ""}.AsSelector(),
},
// pod in namespace "foo"
{
location: buildLocation(
testapi.ResourcePath("pods", "foo", ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
resource: "pods",
namespace: "foo",
fieldSelector: fields.Set{"spec.host": ""}.AsSelector(),
},
}
for _, item := range table {
handler := util.FakeHandler{
StatusCode: 500,
ResponseBody: "",
T: t,
}
server := httptest.NewServer(&handler)
defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()})
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
// This test merely tests that the correct request is made.
lw.List()
handler.ValidateRequest(t, item.location, "GET", nil)
}
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:49,代码来源:listwatch_test.go
示例4: TestDefaultErrorFunc
func TestDefaultErrorFunc(t *testing.T) {
grace := int64(30)
testPod := &api.Pod{
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.PodSpec{
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSClusterFirst,
TerminationGracePeriodSeconds: &grace,
},
}
handler := util.FakeHandler{
StatusCode: 200,
ResponseBody: runtime.EncodeOrDie(latest.Codec, testPod),
T: t,
}
mux := http.NewServeMux()
// FakeHandler musn't be sent requests other than the one you want to test.
mux.Handle(testapi.ResourcePath("pods", "bar", "foo"), &handler)
server := httptest.NewServer(mux)
defer server.Close()
factory := NewConfigFactory(client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()}), nil)
queue := cache.NewFIFO(cache.MetaNamespaceKeyFunc)
podBackoff := podBackoff{
perPodBackoff: map[string]*backoffEntry{},
clock: &fakeClock{},
defaultDuration: 1 * time.Millisecond,
maxDuration: 1 * time.Second,
}
errFunc := factory.makeDefaultErrorFunc(&podBackoff, queue)
errFunc(testPod, nil)
for {
// This is a terrible way to do this but I plan on replacing this
// whole error handling system in the future. The test will time
// out if something doesn't work.
time.Sleep(10 * time.Millisecond)
got, exists, _ := queue.Get(testPod)
if !exists {
continue
}
handler.ValidateRequest(t, testapi.ResourcePath("pods", "bar", "foo"), "GET", nil)
if e, a := testPod, got; !reflect.DeepEqual(e, a) {
t.Errorf("Expected %v, got %v", e, a)
}
break
}
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:48,代码来源:factory_test.go
示例5: TestResourceQuotaGet
func TestResourceQuotaGet(t *testing.T) {
ns := api.NamespaceDefault
resourceQuota := &api.ResourceQuota{
ObjectMeta: api.ObjectMeta{
Name: "abc",
Namespace: "foo",
},
Spec: api.ResourceQuotaSpec{
Hard: api.ResourceList{
api.ResourceCPU: resource.MustParse("100"),
api.ResourceMemory: resource.MustParse("10000"),
api.ResourcePods: resource.MustParse("10"),
api.ResourceServices: resource.MustParse("10"),
api.ResourceReplicationControllers: resource.MustParse("10"),
api.ResourceQuotas: resource.MustParse("10"),
},
},
}
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: resourceQuota},
}
response, err := c.Setup().ResourceQuotas(ns).Get("abc")
c.Validate(t, response, err)
}
开发者ID:leonfs,项目名称:romulus,代码行数:31,代码来源:resource_quotas_test.go
示例6: TestNamespaceList
func TestNamespaceList(t *testing.T) {
namespaceList := &api.NamespaceList{
Items: []api.Namespace{
{
ObjectMeta: api.ObjectMeta{Name: "foo"},
},
},
}
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("namespaces", "", ""),
Body: nil,
},
Response: Response{StatusCode: 200, Body: namespaceList},
}
response, err := c.Setup().Namespaces().List(labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("%#v should be nil.", err)
}
if len(response.Items) != 1 {
t.Errorf("%#v response.Items should have len 1.", response.Items)
}
responseNamespace := response.Items[0]
if e, r := responseNamespace.Name, "foo"; e != r {
t.Errorf("%#v != %#v.", e, r)
}
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:31,代码来源:namespaces_test.go
示例7: TestNamespaceCreate
func TestNamespaceCreate(t *testing.T) {
// we create a namespace relative to another namespace
namespace := &api.Namespace{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath("namespaces", "", ""),
Body: namespace,
},
Response: Response{StatusCode: 200, Body: namespace},
}
// from the source ns, provision a new global namespace "foo"
response, err := c.Setup().Namespaces().Create(namespace)
if err != nil {
t.Errorf("%#v should be nil.", err)
}
if e, a := response.Name, namespace.Name; e != a {
t.Errorf("%#v != %#v.", e, a)
}
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:25,代码来源:namespaces_test.go
示例8: TestListServicesLabels
func TestListServicesLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("services", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{StatusCode: 200,
Body: &api.ServiceList{
Items: []api.Service{
{
ObjectMeta: api.ObjectMeta{
Name: "name",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
Spec: api.ServiceSpec{
Selector: map[string]string{
"one": "two",
},
},
},
},
},
},
}
c.Setup()
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedServiceList, err := c.Services(ns).List(selector)
c.Validate(t, receivedServiceList, err)
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:35,代码来源:services_test.go
示例9: TestListServices
func TestListServices(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("services", ns, ""),
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200,
Body: &api.ServiceList{
Items: []api.Service{
{
ObjectMeta: api.ObjectMeta{
Name: "name",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
Spec: api.ServiceSpec{
Selector: map[string]string{
"one": "two",
},
},
},
},
},
},
}
receivedServiceList, err := c.Setup().Services(ns).List(labels.Everything())
t.Logf("received services: %v %#v", err, receivedServiceList)
c.Validate(t, receivedServiceList, err)
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:32,代码来源:services_test.go
示例10: TestBind
func TestBind(t *testing.T) {
table := []struct {
binding *api.Binding
}{
{binding: &api.Binding{
ObjectMeta: api.ObjectMeta{
Namespace: api.NamespaceDefault,
Name: "foo",
},
Target: api.ObjectReference{
Name: "foohost.kubernetes.mydomain.com",
},
}},
}
for _, item := range table {
handler := util.FakeHandler{
StatusCode: 200,
ResponseBody: "",
T: t,
}
server := httptest.NewServer(&handler)
defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()})
b := binder{client}
if err := b.Bind(item.binding); err != nil {
t.Errorf("Unexpected error: %v", err)
continue
}
expectedBody := runtime.EncodeOrDie(testapi.Codec(), item.binding)
handler.ValidateRequest(t, testapi.ResourcePath("bindings", api.NamespaceDefault, ""), "POST", &expectedBody)
}
}
开发者ID:nvnvrts,项目名称:kubernetes,代码行数:34,代码来源:factory_test.go
示例11: TestCreateController
func TestCreateController(t *testing.T) {
ns := api.NamespaceDefault
requestController := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.ResourcePath(getRCResourceName(), ns, ""), Body: requestController, Query: buildQueryValues(nil)},
Response: Response{
StatusCode: 200,
Body: &api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
Spec: api.ReplicationControllerSpec{
Replicas: 2,
Template: &api.PodTemplateSpec{},
},
},
},
}
receivedController, err := c.Setup().ReplicationControllers(ns).Create(requestController)
c.Validate(t, receivedController, err)
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:27,代码来源:replication_controllers_test.go
示例12: TestPersistentVolumeClaimGet
func TestPersistentVolumeClaimGet(t *testing.T) {
ns := api.NamespaceDefault
persistentVolumeClaim := &api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{
Name: "abc",
Namespace: "foo",
},
Spec: api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
api.ReadOnlyMany,
},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
},
},
},
}
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"),
Query: buildQueryValues(ns, nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: persistentVolumeClaim},
}
response, err := c.Setup().PersistentVolumeClaims(ns).Get("abc")
c.Validate(t, response, err)
}
开发者ID:naxhh,项目名称:heapster,代码行数:32,代码来源:persistentvolumeclaim_test.go
示例13: TestPersistentVolumeGet
func TestPersistentVolumeGet(t *testing.T) {
persistentVolume := &api.PersistentVolume{
ObjectMeta: api.ObjectMeta{
Name: "abc",
Namespace: "foo",
},
Spec: api.PersistentVolumeSpec{
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
},
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{Path: "/foo"},
},
},
}
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: persistentVolume},
}
response, err := c.Setup().PersistentVolumes().Get("abc")
c.Validate(t, response, err)
}
开发者ID:noz-oro,项目名称:kubernetes,代码行数:28,代码来源:persistentvolume_test.go
示例14: TestListPods
func TestListPods(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200,
Body: &api.PodList{
Items: []api.Pod{
{
Status: api.PodStatus{
Phase: api.PodRunning,
},
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
},
},
},
},
}
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, receivedPodList, err)
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:25,代码来源:pods_test.go
示例15: TestEventSearch
func TestEventSearch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("events", "baz", ""),
Query: url.Values{
api.FieldSelectorQueryParam(testapi.Version()): []string{
getInvolvedObjectNameFieldLabel(testapi.Version()) + "=foo,",
"involvedObject.namespace=baz,",
"involvedObject.kind=Pod",
},
api.LabelSelectorQueryParam(testapi.Version()): []string{},
},
},
Response: Response{StatusCode: 200, Body: &api.EventList{}},
}
eventList, err := c.Setup().Events("baz").Search(
&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Namespace: "baz",
SelfLink: testapi.SelfLink("pods", ""),
},
},
)
c.Validate(t, eventList, err)
}
开发者ID:leonfs,项目名称:romulus,代码行数:27,代码来源:events_test.go
示例16: TestLimitRangeGet
func TestLimitRangeGet(t *testing.T) {
ns := api.NamespaceDefault
limitRange := &api.LimitRange{
ObjectMeta: api.ObjectMeta{
Name: "abc",
},
Spec: api.LimitRangeSpec{
Limits: []api.LimitRangeItem{
{
Type: api.LimitTypePod,
Max: api.ResourceList{
api.ResourceCPU: resource.MustParse("100"),
api.ResourceMemory: resource.MustParse("10000"),
},
Min: api.ResourceList{
api.ResourceCPU: resource.MustParse("0"),
api.ResourceMemory: resource.MustParse("100"),
},
},
},
},
}
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"),
Query: buildQueryValues(ns, nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: limitRange},
}
response, err := c.Setup().LimitRanges(ns).Get("abc")
c.Validate(t, response, err)
}
开发者ID:naxhh,项目名称:heapster,代码行数:35,代码来源:limit_ranges_test.go
示例17: TestPersistentVolumeStatusUpdate
func TestPersistentVolumeStatusUpdate(t *testing.T) {
persistentVolume := &api.PersistentVolume{
ObjectMeta: api.ObjectMeta{
Name: "abc",
ResourceVersion: "1",
},
Spec: api.PersistentVolumeSpec{
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
},
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{Path: "/foo"},
},
},
Status: api.PersistentVolumeStatus{
Phase: api.VolumeBound,
Message: "foo",
},
}
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "abc") + "/status",
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolume},
}
response, err := c.Setup().PersistentVolumes().UpdateStatus(persistentVolume)
c.Validate(t, response, err)
}
开发者ID:noz-oro,项目名称:kubernetes,代码行数:29,代码来源:persistentvolume_test.go
示例18: TestInvalidLimitRangeUpdate
func TestInvalidLimitRangeUpdate(t *testing.T) {
ns := api.NamespaceDefault
limitRange := &api.LimitRange{
ObjectMeta: api.ObjectMeta{
Name: "abc",
},
Spec: api.LimitRangeSpec{
Limits: []api.LimitRangeItem{
{
Type: api.LimitTypePod,
Max: api.ResourceList{
api.ResourceCPU: resource.MustParse("100"),
api.ResourceMemory: resource.MustParse("10000"),
},
Min: api.ResourceList{
api.ResourceCPU: resource.MustParse("0"),
api.ResourceMemory: resource.MustParse("100"),
},
},
},
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(ns, nil)},
Response: Response{StatusCode: 200, Body: limitRange},
}
_, err := c.Setup().LimitRanges(ns).Update(limitRange)
if err == nil {
t.Errorf("Expected an error due to missing ResourceVersion")
}
}
开发者ID:naxhh,项目名称:heapster,代码行数:31,代码来源:limit_ranges_test.go
示例19: TestListDaemons
func TestListDaemons(t *testing.T) {
ns := api.NamespaceAll
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getDCResourceName(), ns, ""),
},
Response: Response{StatusCode: 200,
Body: &api.DaemonList{
Items: []api.Daemon{
{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
Spec: api.DaemonSpec{
Template: &api.PodTemplateSpec{},
},
},
},
},
},
}
receivedControllerList, err := c.Setup().Daemons(ns).List(labels.Everything())
c.Validate(t, receivedControllerList, err)
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:30,代码来源:daemon_test.go
示例20: TestUpdateDaemon
func TestUpdateDaemon(t *testing.T) {
ns := api.NamespaceDefault
requestController := &api.Daemon{
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getDCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{
StatusCode: 200,
Body: &api.Daemon{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
Spec: api.DaemonSpec{
Template: &api.PodTemplateSpec{},
},
},
},
}
receivedController, err := c.Setup().Daemons(ns).Update(requestController)
c.Validate(t, receivedController, err)
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:26,代码来源:daemon_test.go
注:本文中的k8s/io/kubernetes/pkg/api/testapi.ResourcePath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论