...
1 package lighthouse
2
3 import (
4 "context"
5 "time"
6
7 v1 "k8s.io/api/core/v1"
8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9 "sigs.k8s.io/controller-runtime/pkg/client/fake"
10
11 "edge-infra.dev/pkg/edge/lighthouse/config"
12 "edge-infra.dev/pkg/edge/lighthouse/testutils"
13 "edge-infra.dev/pkg/lib/gcp/cloudsql"
14 "edge-infra.dev/pkg/lib/logging"
15 )
16
17 func (s *Suite) TestWatchCfg() {
18 ctx := context.Background()
19 cl := fake.NewClientBuilder().Build()
20 dbCfg := cloudsql.PostgresConnection(s.Host, s.Port).DBName(s.Name).Username(s.User).Password(s.Password)
21 customDBCfg := testutils.DialMe{DB: dbCfg}
22 lstner := NewWatchTower().AddListener(customDBCfg, customDBCfg.ConnectionString(), 0, 0, s.Log)
23 syscfg, err := config.Init(context.Background(), cl)
24 s.NoError(err)
25
26 lighthouseConfigmap := &v1.ConfigMap{
27 TypeMeta: metav1.TypeMeta{
28 Kind: "ConfigMap",
29 APIVersion: v1.SchemeGroupVersion.String(),
30 },
31 ObjectMeta: metav1.ObjectMeta{
32 Name: lighthouseConfigMapName,
33 Namespace: lighthouseConfigMapNs,
34 },
35 Data: map[string]string{
36 lighthouseDataFieldName: "cluster_events",
37 },
38 }
39 err = cl.Create(ctx, lighthouseConfigmap)
40 s.NoError(err)
41 log := logging.NewLogger().WithName("lighthouse")
42 watch, err := WatchCfg(ctx, syscfg, lstner, log)
43 s.NoError(err)
44 defer watch.Stop()
45
46 updatedlighthouseConfigmap := &v1.ConfigMap{
47 TypeMeta: metav1.TypeMeta{
48 Kind: "ConfigMap",
49 APIVersion: v1.SchemeGroupVersion.String(),
50 },
51 ObjectMeta: metav1.ObjectMeta{
52 Name: lighthouseConfigMapName,
53 Namespace: lighthouseConfigMapNs,
54 },
55 Data: map[string]string{
56 lighthouseDataFieldName: "cluster_events,banner_events",
57 },
58 }
59 err = cl.Update(ctx, updatedlighthouseConfigmap)
60 s.NoError(err)
61 s.Eventually(func() bool {
62 return lstner.ChannelExists("banner_events")
63 }, 10*time.Second, 5*time.Second)
64 }
65
View as plain text