1 package couchctl
2
3 import (
4 "fmt"
5 "testing"
6
7 "edge-infra.dev/pkg/edge/constants/api/cluster"
8 "edge-infra.dev/pkg/edge/constants/api/fleet"
9 "edge-infra.dev/pkg/edge/datasync/couchdb"
10 "edge-infra.dev/pkg/k8s/testing/kmp"
11 "edge-infra.dev/test/f2"
12 "edge-infra.dev/test/f2/x/ktest"
13
14 "github.com/stretchr/testify/require"
15 corev1 "k8s.io/api/core/v1"
16 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17 )
18
19 func TestStoreServerController(t *testing.T) {
20 fin := f2.NewFeature("CouchServerReconciler Store").
21 WithLabel(_fleetType, fleet.Store).
22 WithLabel(_clusterType, cluster.Generic, cluster.DSDS).
23 Setup("CouchDBServer Exists For Store Server", func(ctx f2.Context, t *testing.T) f2.Context {
24 k := ktest.FromContextT(ctx, t)
25 k.WaitOn(t, k.ObjExists(couchDBServer))
26 return ctx
27 }).
28 Test("Master Replication Secret Exists", func(ctx f2.Context, t *testing.T) f2.Context {
29 k := ktest.FromContextT(ctx, t)
30 secret := secretObj(couchDBServer.Spec.Admin.Credentials.Namespace, couchDBServer.Spec.Admin.Credentials.Name)
31 k.WaitOn(t, k.ObjExists(secret))
32
33 secretKeys := []string{couchdb.SecretUsername, couchdb.SecretPassword, couchdb.SecretCookieName}
34 k.WaitOn(t, k.Check(secret, secretDataExists(secretKeys...)))
35 return ctx
36 }).
37 Test("Embedded Manifests Applied", func(ctx f2.Context, t *testing.T) f2.Context {
38 k := ktest.FromContextT(ctx, t)
39 cm, err := ConfigMap(*couchDBServer)
40 require.NoError(t, err)
41 k.WaitOn(t, k.ObjExists(cm))
42 return ctx
43 }).
44 Test("Store Admin Secret Created", func(ctx f2.Context, t *testing.T) f2.Context {
45 k := ktest.FromContextT(ctx, t)
46 secret := secretObj(couchDBServer.Spec.Admin.Credentials.Namespace, couchDBServer.Spec.Admin.Credentials.Name)
47 k.WaitOn(t, k.ObjExists(secret))
48 secretKeys := []string{couchdb.SecretUsername, couchdb.SecretPassword, couchdb.SecretCookieName, couchdb.SecretAdminsIni}
49 k.WaitOn(t, k.Check(secret, secretDataExists(secretKeys...)))
50 return ctx
51 }).
52 Test("Couchdb Pods Ready", func(ctx f2.Context, t *testing.T) f2.Context {
53 k := ktest.FromContextT(ctx, t)
54 podNum := couchDBServer.Spec.Cluster.Nodes
55 for i := 0; i < podNum; i++ {
56 pod := &corev1.Pod{
57 ObjectMeta: metav1.ObjectMeta{
58 Name: fmt.Sprintf("%s-%d", couchdb.Namespace, i),
59 Namespace: couchdb.Namespace,
60 },
61 }
62 k.WaitOn(t, k.Check(pod, kmp.IsCurrent()))
63 }
64 return ctx
65 }).
66 Test("CouchDBServer Ready", func(ctx f2.Context, t *testing.T) f2.Context {
67 k := ktest.FromContextT(ctx, t)
68 k.WaitOn(t, k.Check(couchDBServer, kmp.IsReady()))
69 return ctx
70 }).
71 Feature()
72
73 f.Test(t, fin)
74 }
75
View as plain text