diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 06bc53eaec5..8d8c821e261 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -308,68 +308,6 @@ func podRunning(c *client.Client, podNamespace string, podName string) wait.Cond } } -func runSelfLinkTestOnNamespace(c *client.Client, namespace string) { - svcBody := api.Service{ - ObjectMeta: api.ObjectMeta{ - Name: "selflinktest", - Namespace: namespace, - Labels: map[string]string{ - "name": "selflinktest", - }, - }, - Spec: api.ServiceSpec{ - // This is here because validation requires it. - Selector: map[string]string{ - "foo": "bar", - }, - Ports: []api.ServicePort{{ - Port: 12345, - Protocol: "TCP", - }}, - SessionAffinity: "None", - }, - } - services := c.Services(namespace) - svc, err := services.Create(&svcBody) - if err != nil { - glog.Fatalf("Failed creating selflinktest service: %v", err) - } - err = c.Get().RequestURI(svc.SelfLink).Do().Into(svc) - if err != nil { - glog.Fatalf("Failed listing service with supplied self link '%v': %v", svc.SelfLink, err) - } - - svcList, err := services.List(api.ListOptions{}) - if err != nil { - glog.Fatalf("Failed listing services: %v", err) - } - - err = c.Get().RequestURI(svcList.SelfLink).Do().Into(svcList) - if err != nil { - glog.Fatalf("Failed listing services with supplied self link '%v': %v", svcList.SelfLink, err) - } - - found := false - for i := range svcList.Items { - item := &svcList.Items[i] - if item.Name != "selflinktest" { - continue - } - found = true - err = c.Get().RequestURI(item.SelfLink).Do().Into(svc) - if err != nil { - glog.Fatalf("Failed listing service with supplied self link '%v': %v", item.SelfLink, err) - } - break - } - if !found { - glog.Fatalf("never found selflinktest service in namespace %s", namespace) - } - glog.Infof("Self link test passed in namespace %s", namespace) - - // TODO: Should test PUT at some point, too. -} - func runAtomicPutTest(c *client.Client) { svcBody := api.Service{ TypeMeta: unversioned.TypeMeta{ @@ -803,10 +741,6 @@ func main() { runAtomicPutTest, runPatchTest, runMasterServiceTest, - func(c *client.Client) { - runSelfLinkTestOnNamespace(c, api.NamespaceDefault) - runSelfLinkTestOnNamespace(c, "other") - }, } // Only run at most maxConcurrency tests in parallel. diff --git a/test/integration/client_test.go b/test/integration/client_test.go index cfa4f5941fd..baa0f7a8646 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -421,3 +421,64 @@ func TestMultiWatch(t *testing.T) { log.Printf("all watches ended") t.Errorf("durations: %v", dur) } + +func runSelfLinkTestOnNamespace(t *testing.T, c *client.Client, namespace string) { + podBody := api.Pod{ + ObjectMeta: api.ObjectMeta{ + Name: "selflinktest", + Namespace: namespace, + Labels: map[string]string{ + "name": "selflinktest", + }, + }, + Spec: api.PodSpec{ + Containers: []api.Container{ + {Name: "name", Image: "image"}, + }, + }, + } + pod, err := c.Pods(namespace).Create(&podBody) + if err != nil { + t.Fatalf("Failed creating selflinktest pod: %v", err) + } + if err = c.Get().RequestURI(pod.SelfLink).Do().Into(pod); err != nil { + t.Errorf("Failed listing pod with supplied self link '%v': %v", pod.SelfLink, err) + } + + podList, err := c.Pods(namespace).List(api.ListOptions{}) + if err != nil { + t.Errorf("Failed listing pods: %v", err) + } + + if err = c.Get().RequestURI(podList.SelfLink).Do().Into(podList); err != nil { + t.Errorf("Failed listing pods with supplied self link '%v': %v", podList.SelfLink, err) + } + + found := false + for i := range podList.Items { + item := &podList.Items[i] + if item.Name != "selflinktest" { + continue + } + found = true + err = c.Get().RequestURI(item.SelfLink).Do().Into(pod) + if err != nil { + t.Errorf("Failed listing pod with supplied self link '%v': %v", item.SelfLink, err) + } + break + } + if !found { + t.Errorf("never found selflinktest pod in namespace %s", namespace) + } +} + +func TestSelfLinkOnNamespace(t *testing.T) { + _, s := framework.RunAMaster(t) + defer s.Close() + + framework.DeleteAllEtcdKeys() + c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) + + runSelfLinkTestOnNamespace(t, c, api.NamespaceDefault) + runSelfLinkTestOnNamespace(t, c, "other-namespace") +}