Skip to content

Commit

Permalink
port test suite from mao
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Dec 3, 2018
1 parent 012575c commit 560711f
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/e2e/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"flag"
"github.com/golang/glog"
"k8s.io/client-go/kubernetes/scheme"
capiv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

const (
namespace = "openshift-cluster-api"
)

func init() {
if err := capiv1alpha1.AddToScheme(scheme.Scheme); err != nil {
glog.Fatal(err)
}
}

type testConfig struct {
client client.Client
}

func newClient() (client.Client, error) {
// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
return nil, err
}

return client.New(cfg, client.Options{})

}

func main() {
flag.Parse()
if err := runSuite(); err != nil {
glog.Fatal(err)
}
}

func runSuite() error {

client, err := newClient()
if err != nil {
return err
}
testConfig := &testConfig{
client: client,
}
glog.Info("RUN: ExpectProviderAvailable")
if err := testConfig.ExpectProviderAvailable(); err != nil {
glog.Errorf("FAIL: ExpectProviderAvailable: %v", err)
return err
}
glog.Info("PASS: ExpectProviderAvailable")

glog.Info("RUN: ExpectOneClusterObject")
if err := testConfig.ExpectOneClusterObject(); err != nil {
glog.Errorf("FAIL: ExpectOneClusterObject: %v", err)
return err
}
glog.Info("PASS: ExpectOneClusterObject")

return nil
}
60 changes: 60 additions & 0 deletions test/e2e/provider_expectations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"time"

"context"
"errors"
"github.com/golang/glog"
kappsapi "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
capiv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
waitShort = 1 * time.Minute
waitMedium = 3 * time.Minute
waitLong = 10 * time.Minute
)

func (tc *testConfig) ExpectProviderAvailable() error {
name := "clusterapi-manager-controllers"
key := types.NamespacedName{
Namespace: namespace,
Name: name,
}
d := &kappsapi.Deployment{}

err := wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
if err := tc.client.Get(context.TODO(), key, d); err != nil {
glog.Errorf("error querying api for Deployment object: %v, retrying...", err)
return false, nil
}
if d.Status.ReadyReplicas < 1 {
return false, nil
}
return true, nil
})
return err
}

func (tc *testConfig) ExpectOneClusterObject() error {
listOptions := client.ListOptions{
Namespace: namespace,
}
clusterList := capiv1alpha1.ClusterList{}

err := wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &clusterList); err != nil {
glog.Errorf("error querying api for clusterList object: %v, retrying...", err)
return false, nil
}
if len(clusterList.Items) != 1 {
return false, errors.New("more than one cluster object found")
}
return true, nil
})
return err
}

0 comments on commit 560711f

Please sign in to comment.