Skip to content

Commit

Permalink
Merge pull request #44543 from jonathanhefner/postgres-structure_load…
Browse files Browse the repository at this point in the history
…-dev_null-to-file_null

Use `File::NULL` instead of `/dev/null`
  • Loading branch information
rafaelfranca committed Feb 24, 2022
2 parents cd4f38b + 88d1915 commit f807513
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def structure_dump(filename, extra_flags)
end

def structure_load(filename, extra_flags)
args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename]
args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename]
args.concat(Array(extra_flags)) if extra_flags
args << db_config.database
run_cmd("psql", args, "loading")
Expand Down
14 changes: 7 additions & 7 deletions activerecord/test/cases/tasks/postgresql_rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def test_structure_load
assert_called_with(
Kernel,
:system,
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]],
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, @configuration["database"]],
returns: true
) do
ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)
Expand All @@ -540,7 +540,7 @@ def test_structure_load

def test_structure_load_with_extra_flags
filename = "awesome-file.sql"
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]

assert_called_with(Kernel, :system, expected_command, returns: true) do
with_structure_load_flags(["--noop"]) do
Expand All @@ -552,7 +552,7 @@ def test_structure_load_with_extra_flags
def test_structure_load_with_env
filename = "awesome-file.sql"
expected_env = { "PGHOST" => "my.server.tld", "PGPORT" => "2345", "PGUSER" => "jane", "PGPASSWORD" => "s3cr3t" }
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]

assert_called_with(Kernel, :system, expected_command, returns: true) do
with_structure_load_flags(["--noop"]) do
Expand All @@ -567,7 +567,7 @@ def test_structure_load_with_env
def test_structure_load_with_ssl_env
filename = "awesome-file.sql"
expected_env = { "PGSSLMODE" => "verify-full", "PGSSLCERT" => "client.crt", "PGSSLKEY" => "client.key", "PGSSLROOTCERT" => "root.crt" }
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]

assert_called_with(Kernel, :system, expected_command, returns: true) do
with_structure_load_flags(["--noop"]) do
Expand All @@ -581,7 +581,7 @@ def test_structure_load_with_ssl_env

def test_structure_load_with_hash_extra_flags_for_a_different_driver
filename = "awesome-file.sql"
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]]
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, @configuration["database"]]

assert_called_with(Kernel, :system, expected_command, returns: true) do
with_structure_load_flags({ mysql2: ["--noop"] }) do
Expand All @@ -592,7 +592,7 @@ def test_structure_load_with_hash_extra_flags_for_a_different_driver

def test_structure_load_with_hash_extra_flags_for_the_correct_driver
filename = "awesome-file.sql"
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]

assert_called_with(Kernel, :system, expected_command, returns: true) do
with_structure_load_flags({ postgresql: ["--noop"] }) do
Expand All @@ -606,7 +606,7 @@ def test_structure_load_accepts_path_with_spaces
assert_called_with(
Kernel,
:system,
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]],
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, @configuration["database"]],
returns: true
) do
ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)
Expand Down

0 comments on commit f807513

Please sign in to comment.