package settings import "testing" func TestRedactDatabaseURL_PostgresURI(t *testing.T) { input := "postgres://vctp_user:Secr3tP%40ss@db-host:5432/vctp?sslmode=disable" got := redactDatabaseURL(input) want := "postgres://vctp_user:REDACTED@db-host:5432/vctp?sslmode=disable" if got != want { t.Fatalf("unexpected redaction result\nwant: %s\ngot: %s", want, got) } } func TestRedactDatabaseURL_PostgresKeyValue(t *testing.T) { input := "host=db-host port=5432 dbname=vctp user=vctp_user password='P@ss:w0rd#%' sslmode=disable" got := redactDatabaseURL(input) want := "host=db-host port=5432 dbname=vctp user=vctp_user password=REDACTED sslmode=disable" if got != want { t.Fatalf("unexpected redaction result\nwant: %s\ngot: %s", want, got) } } func TestRedactDatabaseURL_UnchangedWhenNoPassword(t *testing.T) { input := "host=db-host port=5432 dbname=vctp user=vctp_user sslmode=disable" got := redactDatabaseURL(input) if got != input { t.Fatalf("expected input to remain unchanged\nwant: %s\ngot: %s", input, got) } }