Skip to content

Commit

Permalink
Add e2e and integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lavalamp committed Oct 29, 2014
1 parent 7146ec9 commit 35bd8d4
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
35 changes: 34 additions & 1 deletion cmd/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"os"
"reflect"
"runtime"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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{
Expand All @@ -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

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -438,6 +516,7 @@ func main() {
runAtomicPutTest,
runServiceTest,
runAPIVersionsTest,
runMasterServiceTest,
}
var wg sync.WaitGroup
wg.Add(len(testFuncs))
Expand Down
9 changes: 9 additions & 0 deletions test/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package integration

import (
"net"
"net/http"
"net/http/httptest"
"reflect"
Expand All @@ -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() {
Expand All @@ -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,
Expand Down

0 comments on commit 35bd8d4

Please sign in to comment.