Skip to content

Commit

Permalink
Add a test case using environment variables for connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Jul 26, 2022
1 parent 2525126 commit e982732
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spec/helpers.rb
Expand Up @@ -606,6 +606,17 @@ def run_with_gate(timeout=10)
gate_stop(gate)
end
end

def with_env_vars(**kwargs)
kwargs = kwargs.map{|k,v| [k.to_s, v && v.to_s] }.to_h
old_values = ENV.slice(*kwargs.keys)
ENV.merge!(kwargs)
begin
yield
ensure
ENV.merge!(old_values)
end
end
end


Expand Down
9 changes: 9 additions & 0 deletions spec/pg/connection_spec.rb
Expand Up @@ -318,6 +318,15 @@
tmpconn.finish
end

it "connects with envirinment variables" do
tmpconn = with_env_vars(PGHOST: "localhost", PGPORT: @port, PGDATABASE: "test") do
described_class.connect
end
expect( tmpconn.status ).to eq( PG::CONNECTION_OK )
expect( tmpconn.host ).to eq( "localhost" )
tmpconn.finish
end

it "connects using Hash with multiple hosts", :postgresql_12 do
tmpconn = described_class.connect( host: "#{@unix_socket}xx,127.0.0.1,localhost", port: @port, dbname: "test" )
expect( tmpconn.status ).to eq( PG::CONNECTION_OK )
Expand Down

0 comments on commit e982732

Please sign in to comment.