Skip to content
This repository was archived by the owner on Oct 3, 2019. It is now read-only.

Commit c3ee06f

Browse files
author
Pratik Jagrut
committed
Merge branch 'rewrite.operatorsource.test' of github.com:pratikjagrut/devconsole-operator into rewrite.operatorsource.test
Signed-off-by: Pratik Jagrut <pjagrut@redhat.com>
2 parents 2266d63 + 03914f4 commit c3ee06f

2 files changed

Lines changed: 16 additions & 47 deletions

File tree

test/operatorsource/basic_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ var (
1818
)
1919

2020
func Test_OperatorSource(t *testing.T) {
21-
22-
pod, err := Client.GetPodByLabel(label, namespace)
21+
pods, err := Client.GetPodByLabel(label, namespace)
2322
if err != nil {
2423
t.Fatal(err)
2524
}
26-
defer CleanUp(t, pod)
25+
defer CleanUp(t, &pods.Items[0])
2726
retryInterval := time.Second * 10
2827
timeout := time.Second * 120
2928

30-
err = Client.WaitForOperatorDeployment(t, pod.Name, namespace, retryInterval, timeout)
29+
err = Client.WaitForOperatorDeployment(t, pods.Items[0].Name, namespace, retryInterval, timeout)
3130
if err != nil {
3231
t.Fatal(err)
3332
} else {
@@ -42,23 +41,17 @@ func Subscription(t *testing.T) {
4241
if suberr != nil {
4342
t.Fatal(suberr)
4443
}
45-
fmt.Printf("Subscription Name: %s\nCatalog Source: %s\n", subscription.Name, subscription.Spec.CatalogSource)
4644
require.Equal(t, subName, subscription.Name)
4745
require.Equal(t, "installed-custom-openshift-operators", subscription.Spec.CatalogSource)
4846
}
4947

5048
func InstallPlan(t *testing.T) {
5149
// 2) Find the name of the install plan
5250
installPlanName := subscription.Status.Install.Name
53-
fmt.Printf("Install Plan Name: %s\n", installPlanName)
5451
installPlan, err := Client.GetInstallPlan(installPlanName, namespace)
5552
if err != nil {
5653
t.Fatal(err)
5754
}
58-
fmt.Printf("CSV: %v\n", installPlan.Spec.ClusterServiceVersionNames[0])
59-
fmt.Printf("Install Plan Approval: %v\n", installPlan.Spec.Approval)
60-
fmt.Printf("Install Plan Approved: %v\n", installPlan.Spec.Approved)
61-
6255
require.Equal(t, "devconsole-operator.v0.1.0", installPlan.Spec.ClusterServiceVersionNames[0])
6356
require.Equal(t, "Automatic", string(installPlan.Spec.Approval))
6457
if !installPlan.Spec.Approved {
@@ -68,11 +61,11 @@ func InstallPlan(t *testing.T) {
6861

6962
func OperatorPod(t *testing.T) {
7063
// 3) Check operator pod status, fail status != Running
71-
pod, err := Client.GetPodByLabel(label, namespace)
64+
pods, err := Client.GetPodByLabel(label, namespace)
7265
if err != nil {
7366
t.Fatal(err)
7467
}
75-
fmt.Printf("Pod Name: %v\nPod status: %v\n", pod.Name, pod.Status.Phase)
68+
pod := pods.Items[0]
7669
require.Equal(t, pod.Status.Phase, corev1.PodRunning)
7770
}
7871

test/operatorsource/helpers.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewTestClient() *TestClient {
5656
}
5757

5858
// GetPodByLabel is a function that takes label and namespace and returns the pod and error
59-
func (tc *TestClient) GetPodByLabel(label string, namespace string) (*corev1.Pod, error) {
59+
func (tc *TestClient) GetPodByLabel(label string, namespace string) (*corev1.PodList, error) {
6060

6161
pods, err := tc.K8sClient.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: label})
6262
if err != nil {
@@ -65,7 +65,7 @@ func (tc *TestClient) GetPodByLabel(label string, namespace string) (*corev1.Pod
6565
if len(pods.Items) == 0 {
6666
return nil, nil
6767
}
68-
return &pods.Items[0], nil
68+
return pods, nil
6969
}
7070

7171
//GetSubscription returns subscription struct
@@ -92,45 +92,25 @@ func (tc *TestClient) GetInstallPlan(installPlanName, namespace string) (*apis_v
9292
func (tc *TestClient) Delete(resource, name, namespace string) error {
9393
switch resource {
9494
case "subscription", "sub":
95-
err := tc.OperatorClient.Subscriptions(namespace).Delete(name, &metav1.DeleteOptions{})
96-
if err != nil {
97-
return err
98-
}
99-
return nil
95+
return tc.OperatorClient.Subscriptions(namespace).Delete(name, &metav1.DeleteOptions{})
10096
case "installplan":
101-
err := tc.OperatorClient.InstallPlans(namespace).Delete(name, &metav1.DeleteOptions{})
102-
if err != nil {
103-
return err
104-
}
105-
return nil
106-
case "catalogsource", "catsrc":
107-
err := tc.OperatorClient.CatalogSources(namespace).Delete(name, &metav1.DeleteOptions{})
108-
if err != nil {
109-
return err
110-
}
111-
return nil
97+
return tc.OperatorClient.InstallPlans(namespace).Delete(name, &metav1.DeleteOptions{})
98+
case "catalogsource", "catsrc", "csc":
99+
return tc.OperatorClient.CatalogSources(namespace).Delete(name, &metav1.DeleteOptions{})
112100
case "clusterserviceversion", "csv":
113-
err := tc.OperatorClient.ClusterServiceVersions(namespace).Delete(name, &metav1.DeleteOptions{})
114-
if err != nil {
115-
return err
116-
}
117-
return nil
101+
return tc.OperatorClient.ClusterServiceVersions(namespace).Delete(name, &metav1.DeleteOptions{})
118102
case "pod":
119-
err := tc.K8sClient.CoreV1().Pods(namespace).Delete(name, &metav1.DeleteOptions{})
120-
if err != nil {
121-
return err
122-
}
123-
return nil
103+
return tc.K8sClient.CoreV1().Pods(namespace).Delete(name, &metav1.DeleteOptions{})
124104
default:
125105
option := fmt.Sprintf("Invalid resource: %s", resource)
126106
return errors.New(option)
127107

128108
}
129109
}
130110

131-
//WaitForOperatorDeployment takes pod struct and wait till pods gets in runnig state
111+
//WaitForOperatorDeployment takes pod name and wait till pod gets in runnig state
132112
func (tc *TestClient) WaitForOperatorDeployment(t *testing.T, name, namespace string, retryInterval, timeout time.Duration) error {
133-
err := wait.Poll(retryInterval, timeout, func() (bool, error) {
113+
return wait.Poll(retryInterval, timeout, func() (bool, error) {
134114
pod, err := tc.K8sClient.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
135115
if err != nil {
136116
return false, err
@@ -141,11 +121,7 @@ func (tc *TestClient) WaitForOperatorDeployment(t *testing.T, name, namespace st
141121
if pod.Status.Phase == corev1.PodRunning {
142122
return true, nil
143123
}
144-
t.Logf("Pod %s Status: %s", pod.Name, pod.Status.Phase)
124+
t.Logf("Waiting for pod %s to get running, Current Status: %s\n", pod.Name, pod.Status.Phase)
145125
return false, nil
146126
})
147-
if err != nil {
148-
return err
149-
}
150-
return nil
151127
}

0 commit comments

Comments
 (0)