From 35bd8d4a11c879e045447742fba12c6ca9155854 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Mon, 27 Oct 2014 17:57:28 -0700 Subject: [PATCH] Add e2e and integration tests. --- cmd/e2e/e2e.go | 35 ++++++++++++++- cmd/integration/integration.go | 79 +++++++++++++++++++++++++++++++++ test/integration/client_test.go | 9 ++++ 3 files changed, 122 insertions(+), 1 deletion(-) diff --git a/cmd/e2e/e2e.go b/cmd/e2e/e2e.go index d6dbae931f..a7583ba843 100644 --- a/cmd/e2e/e2e.go +++ b/cmd/e2e/e2e.go @@ -98,6 +98,38 @@ func loadClientOrDie() *client.Client { return c } +func TestKubernetesROService(c *client.Client) bool { + svc := api.ServiceList{} + err := c.Get(). + Namespace("default"). + AbsPath("/api/v1beta1/proxy/services/kubernetes-ro/api/v1beta1/services"). + Do(). + Into(&svc) + if err != nil { + glog.Errorf("unexpected error listing services using ro service: %v", err) + return false + } + var foundRW, foundRO bool + for i := range svc.Items { + if svc.Items[i].Name == "kubernetes" { + foundRW = true + } + if svc.Items[i].Name == "kubernetes-ro" { + foundRO = true + } + } + if !foundRW { + glog.Error("no RW service found") + } + if !foundRO { + glog.Error("no RO service found") + } + if !foundRW || !foundRO { + return false + } + return true +} + func TestPodUpdate(c *client.Client) bool { podClient := c.Pods(api.NamespaceDefault) @@ -158,7 +190,8 @@ func main() { c := loadClientOrDie() tests := []func(c *client.Client) bool{ - // TODO(brendandburns): fix this test and re-add it: TestPodUpdate, + TestKubernetesROService, + // TODO(brendandburns): fix this test and re-add it: TestPodUpdate, } passed := true diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index a29eb8c6a7..dcb787a7b0 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -27,6 +27,8 @@ import ( "os" "reflect" "runtime" + "strconv" + "strings" "sync" "time" @@ -131,6 +133,16 @@ func startComponents(manifestURL string) (apiServerURL string) { if err != nil { glog.Fatalf("Unable to parse CIDR: %v", err) } + glog.Infof("Using portalNet '%v'", portalNet) + + host, port, err := net.SplitHostPort(strings.TrimLeft(apiServer.URL, "http://")) + if err != nil { + glog.Fatalf("Unable to parse URL '%v': %v", apiServer.URL, err) + } + portNumber, err := strconv.Atoi(port) + if err != nil { + glog.Fatalf("Nonnumeric port? %v", err) + } mux := http.NewServeMux() // Create a master and install handlers into mux. master.New(&master.Config{ @@ -142,6 +154,10 @@ func startComponents(manifestURL string) (apiServerURL string) { Mux: mux, EnableLogsSupport: false, APIPrefix: "/api", + + ReadWritePort: portNumber, + ReadOnlyPort: portNumber, + PublicAddress: host, }) handler.delegate = mux @@ -342,6 +358,68 @@ func runAtomicPutTest(c *client.Client) { glog.Info("Atomic PUTs work.") } +func runMasterServiceTest(client *client.Client) { + time.Sleep(12 * time.Second) + var svcList api.ServiceList + err := client.Get(). + Namespace("default"). + Path("services"). + Do(). + Into(&svcList) + if err != nil { + glog.Fatalf("unexpected error listing services: %v", err) + } + var foundRW, foundRO bool + found := util.StringSet{} + for i := range svcList.Items { + found.Insert(svcList.Items[i].Name) + if svcList.Items[i].Name == "kubernetes" { + foundRW = true + } + if svcList.Items[i].Name == "kubernetes-ro" { + foundRO = true + } + } + if foundRW { + var ep api.Endpoints + err := client.Get(). + Namespace("default"). + Path("endpoints"). + Path("kubernetes"). + Do(). + Into(&ep) + if err != nil { + glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err) + } + if len(ep.Endpoints) == 0 { + glog.Fatalf("no endpoints for kubernetes service: %v", ep) + } + } else { + glog.Errorf("no RW service found: %v", found) + } + if foundRO { + var ep api.Endpoints + err := client.Get(). + Namespace("default"). + Path("endpoints"). + Path("kubernetes-ro"). + Do(). + Into(&ep) + if err != nil { + glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err) + } + if len(ep.Endpoints) == 0 { + glog.Fatalf("no endpoints for kubernetes service: %v", ep) + } + } else { + glog.Errorf("no RO service found: %v", found) + } + if !foundRW || !foundRO { + glog.Fatalf("Kubernetes service test failed: %v", found) + } + glog.Infof("Master service test passed.") +} + func runServiceTest(client *client.Client) { pod := api.Pod{ ObjectMeta: api.ObjectMeta{ @@ -438,6 +516,7 @@ func main() { runAtomicPutTest, runServiceTest, runAPIVersionsTest, + runMasterServiceTest, } var wg sync.WaitGroup wg.Add(len(testFuncs)) diff --git a/test/integration/client_test.go b/test/integration/client_test.go index a8de250dec..9cac0f3d5a 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -19,6 +19,7 @@ limitations under the License. package integration import ( + "net" "net/http" "net/http/httptest" "reflect" @@ -29,6 +30,8 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/version" + + "github.com/golang/glog" ) func init() { @@ -41,8 +44,14 @@ func TestClient(t *testing.T) { t.Fatalf("unexpected error: %v", err) } mux := http.NewServeMux() + + _, portalNet, err := net.ParseCIDR("10.0.0.0/24") + if err != nil { + glog.Fatalf("Unable to parse CIDR: %v", err) + } master.New(&master.Config{ EtcdHelper: helper, + PortalNet: portalNet, Mux: mux, EnableLogsSupport: false, EnableUISupport: false,