fix todo: use the ServiceTestJig replace of service

This commit is contained in:
hangaoshuai 2018-02-03 12:06:52 +08:00
parent 230726ffbe
commit 7c7be149d9
2 changed files with 31 additions and 33 deletions

View File

@ -211,6 +211,20 @@ func (j *ServiceTestJig) CreateExternalNameServiceOrFail(namespace string, tweak
return result
}
// CreateServiceWithServicePort creates a new Service with ServicePort.
func (j *ServiceTestJig) CreateServiceWithServicePort(labels map[string]string, namespace string, ports []v1.ServicePort) (*v1.Service, error) {
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: j.Name,
},
Spec: v1.ServiceSpec{
Selector: labels,
Ports: ports,
},
}
return j.Client.CoreV1().Services(namespace).Create(service)
}
func (j *ServiceTestJig) ChangeServiceType(namespace, name string, newType v1.ServiceType, timeout time.Duration) {
ingressIP := ""
svc := j.UpdateServiceOrFail(namespace, name, func(s *v1.Service) {

View File

@ -84,9 +84,9 @@ var _ = SIGDescribe("Services", func() {
valid/accessible endpoints (same port number for service and pods).
*/
framework.ConformanceIt("should serve a basic endpoint from pods ", func() {
// TODO: use the ServiceTestJig here
serviceName := "endpoint-test2"
ns := f.Namespace.Name
jig := framework.NewServiceTestJig(cs, serviceName)
labels := map[string]string{
"foo": "bar",
"baz": "blah",
@ -97,20 +97,12 @@ var _ = SIGDescribe("Services", func() {
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
Expect(err).NotTo(HaveOccurred())
}()
ports := []v1.ServicePort{{
Port: 80,
TargetPort: intstr.FromInt(80),
}}
_, err := jig.CreateServiceWithServicePort(labels, ns, ports)
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: serviceName,
},
Spec: v1.ServiceSpec{
Selector: labels,
Ports: []v1.ServicePort{{
Port: 80,
TargetPort: intstr.FromInt(80),
}},
},
}
_, err := cs.CoreV1().Services(ns).Create(service)
Expect(err).NotTo(HaveOccurred())
framework.ValidateEndpointsOrFail(cs, ns, serviceName, framework.PortsByPodName{})
@ -149,10 +141,10 @@ var _ = SIGDescribe("Services", func() {
valid/accessible endpoints (different port number for pods).
*/
framework.ConformanceIt("should serve multiport endpoints from pods ", func() {
// TODO: use the ServiceTestJig here
// repacking functionality is intentionally not tested here - it's better to test it in an integration test.
serviceName := "multi-endpoint-test"
ns := f.Namespace.Name
jig := framework.NewServiceTestJig(cs, serviceName)
defer func() {
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
@ -165,27 +157,19 @@ var _ = SIGDescribe("Services", func() {
svc2port := "svc2"
By("creating service " + serviceName + " in namespace " + ns)
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: serviceName,
ports := []v1.ServicePort{
{
Name: "portname1",
Port: 80,
TargetPort: intstr.FromString(svc1port),
},
Spec: v1.ServiceSpec{
Selector: labels,
Ports: []v1.ServicePort{
{
Name: "portname1",
Port: 80,
TargetPort: intstr.FromString(svc1port),
},
{
Name: "portname2",
Port: 81,
TargetPort: intstr.FromString(svc2port),
},
},
{
Name: "portname2",
Port: 81,
TargetPort: intstr.FromString(svc2port),
},
}
_, err := cs.CoreV1().Services(ns).Create(service)
_, err := jig.CreateServiceWithServicePort(labels, ns, ports)
Expect(err).NotTo(HaveOccurred())
port1 := 100
port2 := 101