Skip to content

Commit 275e6b6

Browse files
committed
Setup opts for test and add helper function for getting migrations
1 parent 28d53c3 commit 275e6b6

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

test/migration_generator_test.exs

+22-27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ defmodule AshPostgres.MigrationGeneratorTest do
44

55
import ExUnit.CaptureLog
66

7+
alias AshPostgres.MigrationGenerator
8+
79
setup do
810
current_shell = Mix.shell()
911

@@ -1252,13 +1254,17 @@ defmodule AshPostgres.MigrationGeneratorTest do
12521254

12531255
describe "--dev option" do
12541256
setup do
1257+
{snapshot_path, migration_path} = {"test_snapshots_path", "test_migration_path"}
1258+
12551259
on_exit(fn ->
1256-
File.rm_rf!("test_snapshots_path")
1257-
File.rm_rf!("test_migration_path")
1260+
File.rm_rf!(snapshot_path)
1261+
File.rm_rf!(migration_path)
12581262
end)
1263+
1264+
[opts: [snapshot_path: snapshot_path, migration_path: migration_path]]
12591265
end
12601266

1261-
test "generates dev migration" do
1267+
test "generates dev migration", %{opts: opts} do
12621268
defposts do
12631269
attributes do
12641270
uuid_primary_key(:id)
@@ -1268,32 +1274,14 @@ defmodule AshPostgres.MigrationGeneratorTest do
12681274

12691275
defdomain([Post])
12701276

1271-
AshPostgres.MigrationGenerator.generate(Domain,
1272-
snapshot_path: "test_snapshots_path",
1273-
snapshots_only: false,
1274-
migration_path: "test_migration_path",
1275-
dev: true
1276-
)
1277-
1278-
assert [dev_file] =
1279-
Path.wildcard("test_migration_path/**/*_migrate_resources*.exs")
1280-
|> Enum.reject(&String.contains?(&1, "extensions"))
1281-
1277+
assert :ok == MigrationGenerator.generate(Domain, opts ++ [dev: true])
1278+
assert [dev_file] = get_migration_files(opts)
12821279
assert String.contains?(dev_file, "_dev.exs")
1283-
contents = File.read!(dev_file)
1284-
1285-
AshPostgres.MigrationGenerator.generate(Domain,
1286-
snapshot_path: "test_snapshots_path",
1287-
migration_path: "test_migration_path"
1288-
)
1289-
1290-
assert [file] =
1291-
Path.wildcard("test_migration_path/**/*_migrate_resources*.exs")
1292-
|> Enum.reject(&String.contains?(&1, "extensions"))
1293-
1280+
assert {:ok, dev_file_read} = File.read(dev_file)
1281+
assert :ok == MigrationGenerator.generate(Domain, opts)
1282+
assert [file] = get_migration_files(opts)
1283+
assert dev_file_read == File.read!(file)
12941284
refute String.contains?(file, "_dev.exs")
1295-
1296-
assert contents == File.read!(file)
12971285
end
12981286
end
12991287

@@ -2345,4 +2333,11 @@ defmodule AshPostgres.MigrationGeneratorTest do
23452333
~S[modify :post_id, references(:posts, column: :id, name: "comments_post_id_fkey", type: :uuid, prefix: "public")]
23462334
end
23472335
end
2336+
2337+
defp get_migration_files(opts) do
2338+
opts[:migration_path]
2339+
|> Path.join("**/*_migrate_resources*.exs")
2340+
|> Path.wildcard()
2341+
|> Enum.reject(&String.contains?(&1, "extensions"))
2342+
end
23482343
end

0 commit comments

Comments
 (0)