package lighthouse import ( "context" "time" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client/fake" "edge-infra.dev/pkg/edge/lighthouse/config" "edge-infra.dev/pkg/edge/lighthouse/testutils" "edge-infra.dev/pkg/lib/gcp/cloudsql" "edge-infra.dev/pkg/lib/logging" ) func (s *Suite) TestWatchCfg() { ctx := context.Background() cl := fake.NewClientBuilder().Build() dbCfg := cloudsql.PostgresConnection(s.Host, s.Port).DBName(s.Name).Username(s.User).Password(s.Password) customDBCfg := testutils.DialMe{DB: dbCfg} lstner := NewWatchTower().AddListener(customDBCfg, customDBCfg.ConnectionString(), 0, 0, s.Log) syscfg, err := config.Init(context.Background(), cl) s.NoError(err) //create the configmap lighthouseConfigmap := &v1.ConfigMap{ TypeMeta: metav1.TypeMeta{ Kind: "ConfigMap", APIVersion: v1.SchemeGroupVersion.String(), }, ObjectMeta: metav1.ObjectMeta{ Name: lighthouseConfigMapName, Namespace: lighthouseConfigMapNs, }, Data: map[string]string{ lighthouseDataFieldName: "cluster_events", }, } err = cl.Create(ctx, lighthouseConfigmap) s.NoError(err) log := logging.NewLogger().WithName("lighthouse") watch, err := WatchCfg(ctx, syscfg, lstner, log) s.NoError(err) defer watch.Stop() //update the configmap updatedlighthouseConfigmap := &v1.ConfigMap{ TypeMeta: metav1.TypeMeta{ Kind: "ConfigMap", APIVersion: v1.SchemeGroupVersion.String(), }, ObjectMeta: metav1.ObjectMeta{ Name: lighthouseConfigMapName, Namespace: lighthouseConfigMapNs, }, Data: map[string]string{ lighthouseDataFieldName: "cluster_events,banner_events", }, } err = cl.Update(ctx, updatedlighthouseConfigmap) s.NoError(err) s.Eventually(func() bool { return lstner.ChannelExists("banner_events") }, 10*time.Second, 5*time.Second) }