mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 04:14:15 +00:00
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
29 lines
739 B
Go
29 lines
739 B
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgconn"
|
|
)
|
|
|
|
func TestBuildDSNHost(t *testing.T) {
|
|
cases := []struct{ host, want string }{
|
|
{"", "127.0.0.1"},
|
|
{"db.internal", "db.internal"},
|
|
{"10.0.0.5", "10.0.0.5"},
|
|
{"::1", "::1"},
|
|
{"2001:db8::5", "2001:db8::5"},
|
|
{"[2001:db8::5]", "2001:db8::5"},
|
|
}
|
|
for _, tc := range cases {
|
|
dsn := Database{Host: tc.host, Port: 5433, User: "u", DBName: "artex"}.buildDSN()
|
|
cfg, err := pgconn.ParseConfig(dsn)
|
|
if err != nil {
|
|
t.Fatalf("host %q: DSN %q does not parse: %v", tc.host, dsn, err)
|
|
}
|
|
if cfg.Host != tc.want || cfg.Port != 5433 {
|
|
t.Errorf("host %q: pgx reads host %q port %d from %q, want %q 5433", tc.host, cfg.Host, cfg.Port, dsn, tc.want)
|
|
}
|
|
}
|
|
}
|