(t *testing.T)
| 47 | } |
| 48 | |
| 49 | func TestConnect(t *testing.T) { |
| 50 | t.Parallel() |
| 51 | |
| 52 | connString := os.Getenv("PGX_TEST_DATABASE") |
| 53 | config := mustParseConfig(t, connString) |
| 54 | |
| 55 | conn, err := pgx.ConnectConfig(context.Background(), config) |
| 56 | if err != nil { |
| 57 | t.Fatalf("Unable to establish connection: %v", err) |
| 58 | } |
| 59 | |
| 60 | assertConfigsEqual(t, config, conn.Config(), "Conn.Config() returns original config") |
| 61 | |
| 62 | var currentDB string |
| 63 | err = conn.QueryRow(context.Background(), "select current_database()").Scan(¤tDB) |
| 64 | if err != nil { |
| 65 | t.Fatalf("QueryRow Scan unexpectedly failed: %v", err) |
| 66 | } |
| 67 | if currentDB != config.Config.Database { |
| 68 | t.Errorf("Did not connect to specified database (%v)", config.Config.Database) |
| 69 | } |
| 70 | |
| 71 | var user string |
| 72 | err = conn.QueryRow(context.Background(), "select current_user").Scan(&user) |
| 73 | if err != nil { |
| 74 | t.Fatalf("QueryRow Scan unexpectedly failed: %v", err) |
| 75 | } |
| 76 | if user != config.Config.User { |
| 77 | t.Errorf("Did not connect as specified user (%v)", config.Config.User) |
| 78 | } |
| 79 | |
| 80 | err = conn.Close(context.Background()) |
| 81 | if err != nil { |
| 82 | t.Fatal("Unable to close connection") |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func TestConnectWithPreferSimpleProtocol(t *testing.T) { |
| 87 | t.Parallel() |
nothing calls this directly
no test coverage detected