Golang BuildQueryValues示例

说明

golang buildqueryvalues示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: k8s/io/kubernetes/pkg/client/unversioned/testclient/simple

示例#1
文件: services_test.go 项目: ethernetdan/kubernetes

func TestServiceProxyGet(t *testing.T) {
	body := "OK"
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath("services", ns, "service-1") + "/proxy/foo",
			Query:  simple.BuildQueryValues(url.Values{"param-name": []string{"param-value"}}),
		},
		Response: simple.Response{StatusCode: 200, RawBody: &body},
	}
	response, err := c.Setup(t).Services(ns).ProxyGet("", "service-1", "", "foo", map[string]string{"param-name": "param-value"}).DoRaw()
	defer c.Close()
	c.ValidateRaw(t, response, err)

	// With scheme and port specified
	c = &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath("services", ns, "https:service-1:my-port") + "/proxy/foo",
			Query:  simple.BuildQueryValues(url.Values{"param-name": []string{"param-value"}}),
		},
		Response: simple.Response{StatusCode: 200, RawBody: &body},
	}
	response, err = c.Setup(t).Services(ns).ProxyGet("https", "service-1", "my-port", "foo", map[string]string{"param-name": "param-value"}).DoRaw()
	defer c.Close()
	c.ValidateRaw(t, response, err)
}

示例#2
文件: pod_templates_test.go 项目: gabe-ochoa/kubernetes

func TestPodTemplateList(t *testing.T) {
	ns := api.NamespaceDefault
	podTemplateList := &api.PodTemplateList{
		Items: []api.PodTemplate{
			{
				ObjectMeta: api.ObjectMeta{
					Name:      "foo",
					Namespace: ns,
				},
			},
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, ""),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response: simple.Response{StatusCode: 200, Body: podTemplateList},
	}
	response, err := c.Setup(t).PodTemplates(ns).List(api.ListOptions{})
	defer c.Close()
	c.Validate(t, response, err)
}

示例#3
文件: limit_ranges_test.go 项目: johndmulhausen/kubernetes

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 := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response: simple.Response{StatusCode: 200, Body: limitRange},
	}

	response, err := c.Setup(t).LimitRanges(ns).Get("abc")
	c.Validate(t, response, err)
}

示例#4
文件: pods_test.go 项目: CodeJuan/kubernetes

func TestListPodsLabels(t *testing.T) {
	ns := api.NamespaceDefault
	labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String())
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath("pods", ns, ""),
			Query:  simple.BuildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
		Response: simple.Response{
			StatusCode: http.StatusOK,
			Body: &api.PodList{
				Items: []api.Pod{
					{
						Status: api.PodStatus{
							Phase: api.PodRunning,
						},
						ObjectMeta: api.ObjectMeta{
							Labels: map[string]string{
								"foo":  "bar",
								"name": "baz",
							},
						},
					},
				},
			},
		},
	}
	c.Setup(t)
	defer c.Close()
	c.QueryValidator[labelSelectorQueryParamName] = simple.ValidateLabels
	selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
	options := api.ListOptions{LabelSelector: selector}
	receivedPodList, err := c.Pods(ns).List(options)
	c.Validate(t, receivedPodList, err)
}

示例#5
文件: resource_quotas_test.go 项目: gabe-ochoa/kubernetes

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 := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc"),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response: simple.Response{StatusCode: 200, Body: resourceQuota},
	}

	response, err := c.Setup(t).ResourceQuotas(ns).Get("abc")
	defer c.Close()
	c.Validate(t, response, err)
}

示例#6
文件: persistentvolume_test.go 项目: johndmulhausen/kubernetes

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 := &simple.Client{
		Request: simple.Request{
			Method: "PUT",
			Path:   testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc") + "/status",
			Query:  simple.BuildQueryValues(nil)},
		Response: simple.Response{StatusCode: 200, Body: persistentVolume},
	}
	response, err := c.Setup(t).PersistentVolumes().UpdateStatus(persistentVolume)
	c.Validate(t, response, err)
}

示例#7
文件: horizontalpodautoscaler_test.go 项目: ethernetdan/kubernetes

func testHorizontalPodAutoscalerList(t *testing.T, group testapi.TestGroup, resourceGroup string) {
	ns := api.NamespaceDefault
	horizontalPodAutoscalerList := &extensions.HorizontalPodAutoscalerList{
		Items: []extensions.HorizontalPodAutoscaler{
			{
				ObjectMeta: api.ObjectMeta{
					Name:      "foo",
					Namespace: ns,
				},
			},
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   group.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response:      simple.Response{StatusCode: 200, Body: horizontalPodAutoscalerList},
		ResourceGroup: resourceGroup,
	}
	response, err := getHPAClient(t, c, ns, resourceGroup).List(api.ListOptions{})
	defer c.Close()
	c.Validate(t, response, err)
}

示例#8
文件: persistentvolume_test.go 项目: gabe-ochoa/kubernetes

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 := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc"),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response: simple.Response{StatusCode: 200, Body: persistentVolume},
	}

	response, err := c.Setup(t).PersistentVolumes().Get("abc")
	defer c.Close()
	c.Validate(t, response, err)
}

示例#9
文件: jobs_test.go 项目: johndmulhausen/kubernetes

func TestGetJob(t *testing.T) {
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{
			StatusCode: 200,
			Body: &extensions.Job{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
					Labels: map[string]string{
						"foo":  "bar",
						"name": "baz",
					},
				},
				Spec: extensions.JobSpec{
					Template: api.PodTemplateSpec{},
				},
			},
		},
	}
	receivedJob, err := c.Setup(t).Extensions().Jobs(ns).Get("foo")
	c.Validate(t, receivedJob, err)
}

示例#10
文件: jobs_test.go 项目: ethernetdan/kubernetes

func testGetJob(t *testing.T, group testapi.TestGroup, resourceGroup string) {
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   group.ResourcePath(getJobsResourceName(), ns, "foo"),
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{
			StatusCode: 200,
			Body: &extensions.Job{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
					Labels: map[string]string{
						"foo":  "bar",
						"name": "baz",
					},
				},
				Spec: extensions.JobSpec{
					Template: api.PodTemplateSpec{},
				},
			},
		},
		ResourceGroup: resourceGroup,
	}
	receivedJob, err := getJobClient(t, c, ns, resourceGroup).Get("foo")
	defer c.Close()
	c.Validate(t, receivedJob, err)
}

示例#11
文件: ingress_test.go 项目: CodeJuan/kubernetes

func TestGetIngress(t *testing.T) {
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Extensions.ResourcePath(getIngressResourceName(), ns, "foo"),
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{
			StatusCode: 200,
			Body: &extensions.Ingress{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
					Labels: map[string]string{
						"foo":  "bar",
						"name": "baz",
					},
				},
				Spec: extensions.IngressSpec{
					Rules: []extensions.IngressRule{},
				},
			},
		},
	}
	receivedIngress, err := c.Setup(t).Extensions().Ingress(ns).Get("foo")
	defer c.Close()
	c.Validate(t, receivedIngress, err)
}

示例#12
文件: persistentvolumeclaim_test.go 项目: CodeJuan/kubernetes

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 := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response: simple.Response{StatusCode: 200, Body: persistentVolumeClaim},
	}

	response, err := c.Setup(t).PersistentVolumeClaims(ns).Get("abc")
	defer c.Close()
	c.Validate(t, response, err)
}

示例#13
文件: services_test.go 项目: ethernetdan/kubernetes

func TestListServices(t *testing.T) {
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath("services", ns, ""),
			Query:  simple.BuildQueryValues(nil)},
		Response: simple.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(t).Services(ns).List(api.ListOptions{})
	defer c.Close()
	t.Logf("received services: %v %#v", err, receivedServiceList)
	c.Validate(t, receivedServiceList, err)
}

示例#14
文件: horizontalpodautoscaler_test.go 项目: CodeJuan/kubernetes

func TestHorizontalPodAutoscalerList(t *testing.T) {
	ns := api.NamespaceDefault
	horizontalPodAutoscalerList := &autoscaling.HorizontalPodAutoscalerList{
		Items: []autoscaling.HorizontalPodAutoscaler{
			{
				ObjectMeta: api.ObjectMeta{
					Name:      "foo",
					Namespace: ns,
				},
			},
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response:      simple.Response{StatusCode: 200, Body: horizontalPodAutoscalerList},
		ResourceGroup: autoscaling.GroupName,
	}
	response, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).List(api.ListOptions{})
	defer c.Close()
	c.Validate(t, response, err)
}

示例#15
文件: deployment_test.go 项目: gabe-ochoa/kubernetes

func TestDeploymentCreate(t *testing.T) {
	ns := api.NamespaceDefault
	deployment := extensions.Deployment{
		ObjectMeta: api.ObjectMeta{
			Name:      "abc",
			Namespace: ns,
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "POST",
			Path:   testapi.Extensions.ResourcePath(getDeploymentsResoureName(), ns, ""),
			Query:  simple.BuildQueryValues(nil),
			Body:   &deployment,
		},
		Response: simple.Response{StatusCode: 200, Body: &deployment},
	}

	response, err := c.Setup(t).Deployments(ns).Create(&deployment)
	defer c.Close()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	c.Validate(t, response, err)
}

示例#16
文件: horizontalpodautoscaler_test.go 项目: CodeJuan/kubernetes

func TestHorizontalPodAutoscalerCreate(t *testing.T) {
	ns := api.NamespaceDefault
	horizontalPodAutoscaler := autoscaling.HorizontalPodAutoscaler{
		ObjectMeta: api.ObjectMeta{
			Name:      "abc",
			Namespace: ns,
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "POST",
			Path:   testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
			Query:  simple.BuildQueryValues(nil),
			Body:   &horizontalPodAutoscaler,
		},
		Response:      simple.Response{StatusCode: 200, Body: &horizontalPodAutoscaler},
		ResourceGroup: autoscaling.GroupName,
	}

	response, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).Create(&horizontalPodAutoscaler)
	defer c.Close()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	c.Validate(t, response, err)
}

示例#17
文件: nodes_test.go 项目: vikaschoudhary16/kubernetes

func TestListNodesLabels(t *testing.T) {
	labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(registered.GroupOrDie(api.GroupName).GroupVersion.String())
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
			Query:  simple.BuildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
		Response: simple.Response{
			StatusCode: 200,
			Body: &api.NodeList{
				Items: []api.Node{
					{
						ObjectMeta: api.ObjectMeta{
							Labels: map[string]string{
								"foo":  "bar",
								"name": "baz",
							},
						},
					},
				},
			},
		},
	}
	c.Setup(t)
	defer c.Close()
	c.QueryValidator[labelSelectorQueryParamName] = simple.ValidateLabels
	selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
	options := api.ListOptions{LabelSelector: selector}
	receivedNodeList, err := c.Nodes().List(options)
	c.Validate(t, receivedNodeList, err)
}

示例#18
文件: testgroup_test.go 项目: TheRichardPark/kubernetes

func TestListTestTypesLabels(t *testing.T) {
	ns := api.NamespaceDefault
	labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testHelper.GroupVersion().String())
	c := DecoratedSimpleClient{
		simpleClient: simple.Client{
			Request: simple.Request{
				Method: "GET",
				Path:   testHelper.ResourcePath("testtypes", ns, ""),
				Query:  simple.BuildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
			Response: simple.Response{
				StatusCode: http.StatusOK,
				Body: &testgroup.TestTypeList{
					Items: []testgroup.TestType{
						{
							ObjectMeta: api.ObjectMeta{
								Labels: map[string]string{
									"foo":  "bar",
									"name": "baz",
								},
							},
						},
					},
				},
			},
		},
	}
	c.Setup(t)
	c.simpleClient.QueryValidator[labelSelectorQueryParamName] = simple.ValidateLabels
	selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
	options := api.ListOptions{LabelSelector: selector}
	receivedTestTypeList, err := c.TestTypes(ns).List(options)
	c.simpleClient.Validate(t, receivedTestTypeList, err)
}

示例#19
文件: horizontalpodautoscaler_test.go 项目: ethernetdan/kubernetes

func testHorizontalPodAutoscalerCreate(t *testing.T, group testapi.TestGroup, resourceGroup string) {
	ns := api.NamespaceDefault
	horizontalPodAutoscaler := extensions.HorizontalPodAutoscaler{
		ObjectMeta: api.ObjectMeta{
			Name:      "abc",
			Namespace: ns,
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "POST",
			Path:   group.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
			Query:  simple.BuildQueryValues(nil),
			Body:   &horizontalPodAutoscaler,
		},
		Response:      simple.Response{StatusCode: 200, Body: &horizontalPodAutoscaler},
		ResourceGroup: resourceGroup,
	}

	response, err := getHPAClient(t, c, ns, resourceGroup).Create(&horizontalPodAutoscaler)
	defer c.Close()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	c.Validate(t, response, err)
}

示例#20
文件: persistentvolumeclaim_test.go 项目: jsravn/kubernetes

func TestPersistentVolumeClaimStatusUpdate(t *testing.T) {
	ns := api.NamespaceDefault
	persistentVolumeClaim := &api.PersistentVolumeClaim{
		ObjectMeta: api.ObjectMeta{
			Name:            "abc",
			ResourceVersion: "1",
		},
		Spec: api.PersistentVolumeClaimSpec{
			AccessModes: []api.PersistentVolumeAccessMode{
				api.ReadWriteOnce,
				api.ReadOnlyMany,
			},
			Resources: api.ResourceRequirements{
				Requests: api.ResourceList{
					api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
				},
			},
		},
		Status: api.PersistentVolumeClaimStatus{
			Phase: api.ClaimBound,
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "PUT",
			Path:   testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc") + "/status",
			Query:  simple.BuildQueryValues(nil)},
		Response: simple.Response{StatusCode: 200, Body: persistentVolumeClaim},
	}
	response, err := c.Setup(t).PersistentVolumeClaims(ns).UpdateStatus(persistentVolumeClaim)
	c.Validate(t, response, err)
}

示例#21
文件: services_test.go 项目: jsravn/kubernetes

func TestGetService(t *testing.T) {
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath("services", ns, "1"),
			Query:  simple.BuildQueryValues(nil)},
		Response: simple.Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
	}
	response, err := c.Setup(t).Services(ns).Get("1")
	c.Validate(t, response, err)
}

示例#22
文件: jobs_test.go 项目: johndmulhausen/kubernetes

func TestDeleteJob(t *testing.T) {
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "DELETE",
			Path:   testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{StatusCode: 200},
	}
	err := c.Setup(t).Extensions().Jobs(ns).Delete("foo", nil)
	c.Validate(t, nil, err)
}

示例#23
文件: scheduledjobs_test.go 项目: CodeJuan/kubernetes

func TestUpdateScheduledJobStatus(t *testing.T) {
	// scheduled jobs should be tested only when batch/v2alpha1 is enabled
	if *testapi.Batch.GroupVersion() != v2alpha1.SchemeGroupVersion {
		return
	}

	ns := api.NamespaceDefault
	requestScheduledJob := &batch.ScheduledJob{
		ObjectMeta: api.ObjectMeta{
			Name:            "foo",
			Namespace:       ns,
			ResourceVersion: "1",
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "PUT",
			Path:   testapi.Batch.ResourcePath(getScheduledJobsResource(), ns, "foo") + "/status",
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{
			StatusCode: 200,
			Body: &batch.ScheduledJob{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
					Labels: map[string]string{
						"foo":  "bar",
						"name": "baz",
					},
				},
				Spec: batch.ScheduledJobSpec{
					ConcurrencyPolicy: batch.AllowConcurrent,
					JobTemplate: batch.JobTemplateSpec{
						Spec: batch.JobSpec{
							Template: api.PodTemplateSpec{},
						},
					},
				},
				Status: batch.ScheduledJobStatus{
					Active: []api.ObjectReference{{Name: "ref"}},
				},
			},
		},
		ResourceGroup: batch.GroupName,
	}
	receivedScheduledJob, err := c.Setup(t).Batch().ScheduledJobs(ns).UpdateStatus(requestScheduledJob)
	defer c.Close()
	c.Validate(t, receivedScheduledJob, err)
}

示例#24
文件: jobs_test.go 项目: ethernetdan/kubernetes

func testDeleteJob(t *testing.T, group testapi.TestGroup, resourceGroup string) {
	ns := api.NamespaceDefault
	c := &simple.Client{
		Request: simple.Request{
			Method: "DELETE",
			Path:   group.ResourcePath(getJobsResourceName(), ns, "foo"),
			Query:  simple.BuildQueryValues(nil),
		},
		Response:      simple.Response{StatusCode: 200},
		ResourceGroup: resourceGroup,
	}
	err := getJobClient(t, c, ns, resourceGroup).Delete("foo", nil)
	defer c.Close()
	c.Validate(t, nil, err)
}

示例#25
文件: scheduledjobs_test.go 项目: CodeJuan/kubernetes

func TestCreateScheduledJob(t *testing.T) {
	// scheduled jobs should be tested only when batch/v2alpha1 is enabled
	if *testapi.Batch.GroupVersion() != v2alpha1.SchemeGroupVersion {
		return
	}

	ns := api.NamespaceDefault
	requestScheduledJob := &batch.ScheduledJob{
		ObjectMeta: api.ObjectMeta{
			Name:      "foo",
			Namespace: ns,
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "POST",
			Path:   testapi.Batch.ResourcePath(getScheduledJobsResource(), ns, ""),
			Body:   requestScheduledJob,
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{
			StatusCode: 200,
			Body: &batch.ScheduledJob{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
					Labels: map[string]string{
						"foo":  "bar",
						"name": "baz",
					},
				},
				Spec: batch.ScheduledJobSpec{
					JobTemplate: batch.JobTemplateSpec{
						Spec: batch.JobSpec{
							Template: api.PodTemplateSpec{},
						},
					},
				},
			},
		},
		ResourceGroup: batch.GroupName,
	}
	receivedScheduledJob, err := c.Setup(t).Batch().ScheduledJobs(ns).Create(requestScheduledJob)
	defer c.Close()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	c.Validate(t, receivedScheduledJob, err)
}

示例#26
文件: ingress_test.go 项目: CodeJuan/kubernetes

func TestUpdateIngressStatus(t *testing.T) {
	ns := api.NamespaceDefault
	lbStatus := api.LoadBalancerStatus{
		Ingress: []api.LoadBalancerIngress{
			{IP: "127.0.0.1"},
		},
	}
	requestIngress := &extensions.Ingress{
		ObjectMeta: api.ObjectMeta{
			Name:            "foo",
			Namespace:       ns,
			ResourceVersion: "1",
		},
		Status: extensions.IngressStatus{
			LoadBalancer: lbStatus,
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "PUT",
			Path:   testapi.Extensions.ResourcePath(getIngressResourceName(), ns, "foo") + "/status",
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{
			StatusCode: 200,
			Body: &extensions.Ingress{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
					Labels: map[string]string{
						"foo":  "bar",
						"name": "baz",
					},
				},
				Spec: extensions.IngressSpec{
					Rules: []extensions.IngressRule{},
				},
				Status: extensions.IngressStatus{
					LoadBalancer: lbStatus,
				},
			},
		},
	}
	receivedIngress, err := c.Setup(t).Extensions().Ingress(ns).UpdateStatus(requestIngress)
	defer c.Close()
	c.Validate(t, receivedIngress, err)
}

示例#27
文件: services_test.go 项目: ethernetdan/kubernetes

func TestUpdateServiceStatus(t *testing.T) {
	ns := api.NamespaceDefault
	lbStatus := api.LoadBalancerStatus{
		Ingress: []api.LoadBalancerIngress{
			{IP: "127.0.0.1"},
		},
	}
	requestService := &api.Service{
		ObjectMeta: api.ObjectMeta{
			Name:            "foo",
			Namespace:       ns,
			ResourceVersion: "1",
		},
		Status: api.ServiceStatus{
			LoadBalancer: lbStatus,
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "PUT",
			Path:   testapi.Default.ResourcePath("services", ns, "foo") + "/status",
			Query:  simple.BuildQueryValues(nil),
		},
		Response: simple.Response{
			StatusCode: 200,
			Body: &api.Service{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
					Labels: map[string]string{
						"foo":  "bar",
						"name": "baz",
					},
				},
				Spec: api.ServiceSpec{},
				Status: api.ServiceStatus{
					LoadBalancer: lbStatus,
				},
			},
		},
	}
	receivedService, err := c.Setup(t).Services(ns).UpdateStatus(requestService)
	defer c.Close()
	c.Validate(t, receivedService, err)
}

示例#28
文件: securitycontextconstraints_test.go 项目: erinboyd/origin

func TestSecurityContextConstraintsGet(t *testing.T) {
	ns := api.NamespaceNone
	scc := &api.SecurityContextConstraints{
		ObjectMeta: api.ObjectMeta{
			Name: "abc",
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Default.ResourcePath(getSCCResoureName(), ns, "abc"),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response: simple.Response{StatusCode: 200, Body: scc},
	}

	response, err := c.Setup(t).SecurityContextConstraints().Get("abc")
	c.Validate(t, response, err)
}

示例#29
文件: deployment_test.go 项目: ethernetdan/kubernetes

func TestDeploymentRollback(t *testing.T) {
	ns := api.NamespaceDefault
	deploymentRollback := &extensions.DeploymentRollback{
		Name:               "abc",
		UpdatedAnnotations: map[string]string{},
		RollbackTo:         extensions.RollbackConfig{Revision: 1},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "POST",
			Path:   testapi.Extensions.ResourcePath(getDeploymentsResourceName(), ns, "abc") + "/rollback",
			Query:  simple.BuildQueryValues(nil),
			Body:   deploymentRollback,
		},
		Response: simple.Response{StatusCode: http.StatusOK},
	}
	err := c.Setup(t).Deployments(ns).Rollback(deploymentRollback)
	defer c.Close()
	c.ValidateCommon(t, err)
}

示例#30
文件: podsecuritypolicy_test.go 项目: ethernetdan/kubernetes

func TestPodSecurityPolicyGet(t *testing.T) {
	ns := api.NamespaceNone
	scc := &extensions.PodSecurityPolicy{
		ObjectMeta: api.ObjectMeta{
			Name: "abc",
		},
	}
	c := &simple.Client{
		Request: simple.Request{
			Method: "GET",
			Path:   testapi.Extensions.ResourcePath(getPSPResourcename(), ns, "abc"),
			Query:  simple.BuildQueryValues(nil),
			Body:   nil,
		},
		Response: simple.Response{StatusCode: 200, Body: scc},
	}

	response, err := c.Setup(t).PodSecurityPolicies().Get("abc")
	c.Validate(t, response, err)
}

展开阅读全文