Skip to content

Commit e1d1d43

Browse files
committed
refactor: update test, rename variables & remove bin files
Signed-off-by: Imtiaz Uddin <imtiaz@appscode.com>
1 parent d593e92 commit e1d1d43

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

apis/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type ListenerCfg struct {
4141
type PublisherCfg struct {
4242
Type PublisherType `valid:"required" json:"type" mapstructure:"type"`
4343
Address string `valid:"required" json:"address" mapstructure:"address"`
44-
NatsCredPath string `json:"natsCredPath" mapstructure:"natsCredPath"`
44+
NatsCredPath string `valid:"required" json:"natsCredPath" mapstructure:"natsCredPath"`
4545
Topic string `valid:"required" json:"topic" mapstructure:"topic"`
4646
TopicPrefix string `json:"topicPrefix" mapstructure:"topicPrefix"`
4747
EnableTLS bool `json:"enableTLS" mapstructure:"enableTlS"`

apis/config_test.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ func TestConfig_Validate(t *testing.T) {
3939
Password: "pass",
4040
},
4141
Publisher: &PublisherCfg{
42-
Type: "kafka",
43-
Address: "addr",
44-
Topic: "stream",
45-
TopicPrefix: "prefix",
42+
Type: "kafka",
43+
Address: "addr",
44+
Topic: "stream",
45+
TopicPrefix: "prefix",
46+
NatsCredPath: "/etc/nats/creds/admin.creds",
4647
},
4748
},
4849
wantErr: nil,
@@ -65,10 +66,11 @@ func TestConfig_Validate(t *testing.T) {
6566
Password: "pass",
6667
},
6768
Publisher: &PublisherCfg{
68-
Type: "kafka",
69-
Address: "addr",
70-
Topic: "stream",
71-
TopicPrefix: "prefix",
69+
Type: "kafka",
70+
Address: "addr",
71+
Topic: "stream",
72+
TopicPrefix: "prefix",
73+
NatsCredPath: "/etc/nats/creds/admin.creds",
7274
},
7375
},
7476
wantErr: errors.New("Listener.refreshConnection: non zero value required;Listener.slotName: non zero value required"),
@@ -91,10 +93,11 @@ func TestConfig_Validate(t *testing.T) {
9193
Password: "pass",
9294
},
9395
Publisher: &PublisherCfg{
94-
Type: "kafka",
95-
Address: "addr",
96-
Topic: "stream",
97-
TopicPrefix: "prefix",
96+
Type: "kafka",
97+
Address: "addr",
98+
Topic: "stream",
99+
TopicPrefix: "prefix",
100+
NatsCredPath: "/etc/nats/creds/admin.creds",
98101
},
99102
},
100103
wantErr: errors.New("Database.host: non zero value required;Database.port: non zero value required"),
@@ -119,8 +122,9 @@ func TestConfig_Validate(t *testing.T) {
119122
Password: "pass",
120123
},
121124
Publisher: &PublisherCfg{
122-
Topic: "stream",
123-
TopicPrefix: "prefix",
125+
Topic: "stream",
126+
TopicPrefix: "prefix",
127+
NatsCredPath: "/etc/nats/creds/admin.creds",
124128
},
125129
},
126130
wantErr: errors.New("Publisher.address: non zero value required;Publisher.type: non zero value required"),

cmd/pgoutbox/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ func main() {
8585

8686
logger := apis.InitSlog(cfg.Logger, version, false)
8787

88-
conn, rConn, err := initPgxConnections(cfg.Database, logger, time.Minute*10)
88+
pgxConn, pgConn, err := initPgxConnections(cfg.Database, logger, time.Minute*10)
8989
if err != nil {
9090
return fmt.Errorf("pgx connection: %w", err)
9191
}
9292

93-
if err = configureReplicaIdentityToFull(ctx, conn, cfg.Listener.Filter); err != nil {
93+
if err = configureReplicaIdentityToFull(ctx, pgxConn, cfg.Listener.Filter); err != nil {
9494
return fmt.Errorf("configure replica identity: %w", err)
9595
}
9696
pub, err := factoryPublisher(ctx, cfg.Publisher, logger)
@@ -107,8 +107,8 @@ func main() {
107107
svc := listener.NewWalListener(
108108
cfg,
109109
logger,
110-
listener.NewRepository(conn),
111-
newReplicationConn(rConn),
110+
listener.NewRepository(pgxConn),
111+
newReplicationConn(pgConn),
112112
pub,
113113
transaction.NewBinaryParser(logger, binary.BigEndian),
114114
apis.NewMetrics(),

internal/listener/listener.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ func (l *Listener) liveness(w http.ResponseWriter, _ *http.Request) {
143143
respCode = http.StatusInternalServerError
144144

145145
l.log.Warn("liveness probe failed")
146+
} else {
147+
l.log.Debug("liveness probe successful")
146148
}
147149

148150
w.WriteHeader(respCode)
@@ -165,6 +167,8 @@ func (l *Listener) readiness(w http.ResponseWriter, _ *http.Request) {
165167
respCode = http.StatusInternalServerError
166168

167169
l.log.Warn("readiness probe failed")
170+
} else {
171+
l.log.Debug("readiness probe successful")
168172
}
169173

170174
w.WriteHeader(respCode)

pgoutbox

-34.1 MB
Binary file not shown.

wal-listener

-35.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)