Skip to content

Commit

Permalink
pgloader: fix ENV["CI"] usage.
Browse files Browse the repository at this point in the history
Part of #70493.
  • Loading branch information
MikeMcQuaid committed Feb 8, 2021
1 parent 1db9b89 commit faa1b2b
Showing 1 changed file with 0 additions and 63 deletions.
63 changes: 0 additions & 63 deletions Formula/pgloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,6 @@ def install
system "make"
bin.install "bin/pgloader"
end

def launch_postgres(socket_dir)
require "timeout"

socket_dir = Pathname.new(socket_dir)
mkdir_p socket_dir

postgres_command = [
"postgres",
"--listen_addresses=",
"--unix_socket_directories=#{socket_dir}",
]

IO.popen(postgres_command * " ") do |postgres|
ohai postgres_command * " "
# Postgres won't create the socket until it's ready for connections, but
# if it fails to start, we'll be waiting for the socket forever. So we
# time out quickly; this is simpler than mucking with child process
# signals.
Timeout.timeout(5) { sleep 0.2 while socket_dir.children.empty? }
yield
ensure
Process.kill(:TERM, postgres.pid)
end
end

test do
return if ENV["CI"]

# Remove any Postgres environment variables that might prevent us from
# isolating this disposable copy of Postgres.
ENV.reject! { |key, _| key.start_with?("PG") }

ENV["PGDATA"] = testpath/"data"
ENV["PGHOST"] = testpath/"socket"
ENV["PGDATABASE"] = "brew"

(testpath/"test.load").write <<~EOS
LOAD CSV
FROM inline (code, country)
INTO postgresql:///#{ENV["PGDATABASE"]}?tablename=csv
WITH fields terminated by ','
BEFORE LOAD DO
$$ CREATE TABLE csv (code char(2), country text); $$;
GB,United Kingdom
US,United States
CA,Canada
US,United States
GB,United Kingdom
CA,Canada
EOS

system "initdb"

launch_postgres(ENV["PGHOST"]) do
system "createdb"
system "#{bin}/pgloader", testpath/"test.load"
output = shell_output("psql -Atc 'SELECT COUNT(*) FROM csv'")
assert_equal "6", output.lines.last.chomp
end
end
end
__END__
--- a/local-projects/cl-csv/parser.lisp
Expand Down

0 comments on commit faa1b2b

Please sign in to comment.