add PATCH test

This commit is contained in:
Felix Kunde 2021-10-11 11:22:55 +02:00
parent c49974c166
commit 3b249648a5
1 changed files with 29 additions and 0 deletions

View File

@ -194,3 +194,32 @@ func TestGetConfig(t *testing.T) {
t.Errorf("Postgre parameters differ: expected: %#v, got: %#v", expectedPgParameters, pgParameters)
}
}
func TestSetPostgresParameters(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
parametersToSet := map[string]string{
"max_connections": "50",
"wal_level": "logical",
}
configJson := `{"loop_wait": 10, "maximum_lag_on_failover": 33554432, "postgresql": {"parameters": {"archive_mode": "on", "archive_timeout": "1800s", "autovacuum_analyze_scale_factor": 0.02, "autovacuum_max_workers": 5, "autovacuum_vacuum_scale_factor": 0.05, "checkpoint_completion_target": 0.9, "hot_standby": "on", "log_autovacuum_min_duration": 0, "log_checkpoints": "on", "log_connections": "on", "log_disconnections": "on", "log_line_prefix": "%t [%p]: [%l-1] %c %x %d %u %a %h ", "log_lock_waits": "on", "log_min_duration_statement": 500, "log_statement": "ddl", "log_temp_files": 0, "max_connections": 50, "max_replication_slots": 10, "max_wal_senders": 10, "tcp_keepalives_idle": 900, "tcp_keepalives_interval": 100, "track_functions": "all", "wal_level": "logical", "wal_log_hints": "on"}, "use_pg_rewind": true, "use_slots": true}, "retry_timeout": 10, "slots": {"cdc": {"database": "foo", "plugin": "wal2json", "type": "logical"}}, "ttl": 30}`
r := ioutil.NopCloser(bytes.NewReader([]byte(configJson)))
response := http.Response{
StatusCode: 200,
Body: r,
}
mockClient := mocks.NewMockHTTPClient(ctrl)
mockClient.EXPECT().Do(gomock.Any()).Return(&response, nil)
p := New(logger, mockClient)
err := p.SetPostgresParameters(newMockPod("192.168.100.1"), parametersToSet)
if err != nil {
t.Errorf("could not call patch Patroni config: %v", err)
}
}