package couchctl import ( "fmt" "testing" "edge-infra.dev/pkg/edge/constants/api/cluster" "edge-infra.dev/pkg/edge/constants/api/fleet" "edge-infra.dev/pkg/edge/datasync/couchdb" "edge-infra.dev/pkg/k8s/testing/kmp" "edge-infra.dev/test/f2" "edge-infra.dev/test/f2/x/ktest" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestStoreServerController(t *testing.T) { fin := f2.NewFeature("CouchServerReconciler Store"). WithLabel(_fleetType, fleet.Store). WithLabel(_clusterType, cluster.Generic, cluster.DSDS). Setup("CouchDBServer Exists For Store Server", func(ctx f2.Context, t *testing.T) f2.Context { k := ktest.FromContextT(ctx, t) k.WaitOn(t, k.ObjExists(couchDBServer)) return ctx }). Test("Master Replication Secret Exists", func(ctx f2.Context, t *testing.T) f2.Context { k := ktest.FromContextT(ctx, t) secret := secretObj(couchDBServer.Spec.Admin.Credentials.Namespace, couchDBServer.Spec.Admin.Credentials.Name) k.WaitOn(t, k.ObjExists(secret)) secretKeys := []string{couchdb.SecretUsername, couchdb.SecretPassword, couchdb.SecretCookieName} k.WaitOn(t, k.Check(secret, secretDataExists(secretKeys...))) return ctx }). Test("Embedded Manifests Applied", func(ctx f2.Context, t *testing.T) f2.Context { k := ktest.FromContextT(ctx, t) cm, err := ConfigMap(*couchDBServer) require.NoError(t, err) k.WaitOn(t, k.ObjExists(cm)) return ctx }). Test("Store Admin Secret Created", func(ctx f2.Context, t *testing.T) f2.Context { k := ktest.FromContextT(ctx, t) secret := secretObj(couchDBServer.Spec.Admin.Credentials.Namespace, couchDBServer.Spec.Admin.Credentials.Name) k.WaitOn(t, k.ObjExists(secret)) secretKeys := []string{couchdb.SecretUsername, couchdb.SecretPassword, couchdb.SecretCookieName, couchdb.SecretAdminsIni} k.WaitOn(t, k.Check(secret, secretDataExists(secretKeys...))) return ctx }). Test("Couchdb Pods Ready", func(ctx f2.Context, t *testing.T) f2.Context { k := ktest.FromContextT(ctx, t) podNum := couchDBServer.Spec.Cluster.Nodes for i := 0; i < podNum; i++ { pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-%d", couchdb.Namespace, i), Namespace: couchdb.Namespace, }, } k.WaitOn(t, k.Check(pod, kmp.IsCurrent())) } return ctx }). Test("CouchDBServer Ready", func(ctx f2.Context, t *testing.T) f2.Context { k := ktest.FromContextT(ctx, t) k.WaitOn(t, k.Check(couchDBServer, kmp.IsReady())) return ctx }). Feature() f.Test(t, fin) }