Skip to content

Commit 18dbd16

Browse files
varshaprasad96ankitathomas
authored andcommitted
add e2e tests
Signed-off-by: Varsha Prasad Narsing <[email protected]>
1 parent 4f835fe commit 18dbd16

File tree

4 files changed

+42
-76
lines changed

4 files changed

+42
-76
lines changed

test/e2e/catalogsource_install_test.go

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"strings"
8-
"time"
97

108
. "github.com/onsi/gomega"
11-
"google.golang.org/grpc"
12-
"google.golang.org/grpc/connectivity"
13-
"google.golang.org/grpc/credentials/insecure"
149

1510
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1611
corev1 "k8s.io/api/core/v1"
@@ -154,48 +149,46 @@ func createTestRegistryService(ctx context.Context, cli client.Client, namespace
154149
TargetPort: intstr.FromInt(50051),
155150
},
156151
},
157-
Type: corev1.ServiceTypeNodePort,
158152
Selector: map[string]string{"catalogsource": "prometheus-index"},
159153
},
160154
}
161155
err := c.Create(ctx, svc)
162156
Expect(err).To(BeNil())
163157

164-
conn, err := grpc.Dial(getServiceAddress(ctx, cli, namespace, svc.Name), []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}...)
165-
Expect(err).ToNot(HaveOccurred())
166-
167-
defer conn.Close()
168-
oldState := conn.GetState()
169-
Eventually(func(g Gomega) {
170-
state := conn.GetState()
171-
if state != connectivity.Ready {
172-
if conn.WaitForStateChange(ctx, conn.GetState()) {
173-
state = conn.GetState()
174-
if oldState != state {
175-
oldState = state
176-
if state == connectivity.Idle {
177-
conn.Connect()
178-
}
179-
}
180-
}
181-
}
182-
g.Expect(conn.GetState()).To(Equal(connectivity.Ready))
183-
}).WithTimeout(2 * time.Minute).Should(Succeed())
158+
// svcAddress := getServiceAddress(ctx, cli, namespace, svc.Name)
159+
160+
// conn, err := grpc.Dial(svcAddress, grpc.WithInsecure())
161+
// Expect(err).ToNot(HaveOccurred())
162+
163+
// fmt.Println("svcAddress", svcAddress)
164+
// connectionContext, cancel := context.WithTimeout(context.Background(), 30*time.Second)
165+
// defer cancel()
166+
167+
// defer conn.Close()
168+
// oldState := conn.GetState()
169+
// Eventually(func(g Gomega) {
170+
// state := conn.GetState()
171+
// if state != connectivity.Ready {
172+
// if conn.WaitForStateChange(connectionContext, conn.GetState()) {
173+
// state = conn.GetState()
174+
// if oldState != state {
175+
// oldState = state
176+
// if state == connectivity.Idle {
177+
// conn.Connect()
178+
// }
179+
// }
180+
// }
181+
// }
182+
// g.Expect(conn.GetState()).To(Equal(connectivity.Ready))
183+
// }).WithTimeout(2 * time.Minute).Should(Succeed())
184184
return svc.Name
185185
}
186186

187187
func getServiceAddress(ctx context.Context, cli client.Client, namespace, name string) string {
188188
svc := corev1.Service{}
189189
err := cli.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, &svc)
190190
Expect(err).To(BeNil())
191-
c := config.GetConfigOrDie()
192-
parts := strings.Split(c.Host, ":")
193-
address := parts[0]
194-
if len(parts) == 3 {
195-
address = strings.TrimLeft(parts[1], "/")
196-
}
197-
// TODO: not required on-cluster, fix Dockerfile and use fmt.Sprintf("%s.%s.svc:%d", svc.Name, svc.Namespace, svc.Spec.Ports[0].Port)
198-
return fmt.Sprintf("%s:%d", address, svc.Spec.Ports[0].NodePort)
191+
return fmt.Sprintf("%s.%s.svc:%d", svc.Name, svc.Namespace, svc.Spec.Ports[0].Port)
199192
}
200193

201194
func applyCRDifNotPresent(ctx context.Context) func() {

test/e2e/catsrc_install_test.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/e2e/e2e_suite_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
. "github.com/onsi/ginkgo/v2"
88
. "github.com/onsi/gomega"
9+
corev1 "k8s.io/api/core/v1"
910
"k8s.io/apimachinery/pkg/runtime"
1011
"k8s.io/client-go/rest"
1112
ctrl "sigs.k8s.io/controller-runtime"
@@ -41,6 +42,9 @@ var _ = BeforeSuite(func() {
4142
err = catsrcapi.AddToScheme(scheme)
4243
Expect(err).NotTo(HaveOccurred())
4344

45+
err = corev1.AddToScheme(scheme)
46+
Expect(err).NotTo(HaveOccurred())
47+
4448
c, err = client.New(cfg, client.Options{Scheme: scheme})
4549
Expect(err).To(Not(HaveOccurred()))
4650
})

test/e2e/install_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ var _ = Describe("Operator Install", func() {
2828
operator *operatorv1alpha1.Operator
2929
)
3030

31-
// var kubeClient *kubernetes.Clientset
3231
var testNamespace string
3332
cleanup := func() {}
3433
ctx = context.TODO()
34+
BeforeEach(func() {
35+
testNamespace := createTestNamespace(ctx, c, "registry-grpc-")
36+
cleanup = applyCRDifNotPresent(ctx)
37+
testPrefix := "registry-grpc-"
38+
39+
serviceAccountName := createTestServiceAccount(ctx, c, testNamespace, testPrefix)
40+
createTestRegistryPod(ctx, c, testNamespace, testPrefix, serviceAccountName)
41+
serviceName := createTestRegistryService(ctx, c, testNamespace, testPrefix)
42+
createTestCatalogSource(ctx, c, testNamespace, "prometheus-index", serviceName)
43+
44+
})
3545
AfterEach(func() {
3646
deleteTestNamespace(ctx, c, testNamespace)
3747
cleanup()

0 commit comments

Comments
 (0)