|
| 1 | +package asherah |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestRedactConnectionStringMysqlWithPassword(t *testing.T) { |
| 6 | + result := redactConnectionString("user:secret@tcp(localhost:3306)/db") |
| 7 | + expected := "user:***@tcp(localhost:3306)/db" |
| 8 | + if result != expected { |
| 9 | + t.Errorf("Expected %q, got %q", expected, result) |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +func TestRedactConnectionStringMysqlWithoutPassword(t *testing.T) { |
| 14 | + result := redactConnectionString("user@tcp(localhost:3306)/db") |
| 15 | + expected := "user@tcp(localhost:3306)/db" |
| 16 | + if result != expected { |
| 17 | + t.Errorf("Expected %q, got %q", expected, result) |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +func TestRedactConnectionStringPostgresWithPassword(t *testing.T) { |
| 22 | + result := redactConnectionString("postgres://user:secret@localhost:5432/db") |
| 23 | + expected := "postgres://user:***@localhost:5432/db" |
| 24 | + if result != expected { |
| 25 | + t.Errorf("Expected %q, got %q", expected, result) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +func TestRedactConnectionStringPostgresWithoutPassword(t *testing.T) { |
| 30 | + result := redactConnectionString("postgres://user@localhost:5432/db") |
| 31 | + expected := "postgres://user@localhost:5432/db" |
| 32 | + if result != expected { |
| 33 | + t.Errorf("Expected %q, got %q", expected, result) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func TestRedactConnectionStringEmpty(t *testing.T) { |
| 38 | + result := redactConnectionString("") |
| 39 | + if result != "" { |
| 40 | + t.Errorf("Expected empty string, got %q", result) |
| 41 | + } |
| 42 | +} |
0 commit comments