From 56b4b26849c4a1e2f0acfda8579f457f3abc657d Mon Sep 17 00:00:00 2001 From: woylie <13847569+woylie@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:28:07 +0900 Subject: [PATCH] add integration_test folder to formatter config, format --- .formatter.exs | 5 ++- integration_test/cases/flop_test.exs | 50 +++++++++++++------------ integration_test/pg/all_test.exs | 2 +- integration_test/pg/test_helper.exs | 7 ++-- integration_test/sqlite/all_test.exs | 2 +- integration_test/sqlite/migration.exs | 42 ++++++++++----------- integration_test/sqlite/test_helper.exs | 11 +++--- 7 files changed, 63 insertions(+), 56 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index 16d5948a..2e761db4 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,6 +1,9 @@ # Used by "mix format" [ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], + inputs: [ + "{mix,.formatter}.exs", + "{config,integration_test,lib,test}/**/*.{ex,exs}" + ], line_length: 80, import_deps: [:ecto, :stream_data] ] diff --git a/integration_test/cases/flop_test.exs b/integration_test/cases/flop_test.exs index b67b9814..9b776951 100644 --- a/integration_test/cases/flop_test.exs +++ b/integration_test/cases/flop_test.exs @@ -1,14 +1,16 @@ defmodule Flop.Integration.FlopTest do - use Flop.Integration.Case, async: Application.compile_env(:flop, :async_integration_tests, true) + use Flop.Integration.Case, + async: Application.compile_env(:flop, :async_integration_tests, true) + use ExUnitProperties - + doctest Flop, import: true - + import Ecto.Query import Flop.Factory import Flop.Generators import Flop.TestUtil - + alias __MODULE__.TestProvider alias Ecto.Query.QueryExpr alias Flop.Filter @@ -16,19 +18,19 @@ defmodule Flop.Integration.FlopTest do alias Flop.Repo alias MyApp.Owner alias MyApp.Pet - + @pet_count_range 1..200 - + defmodule TestProvider do use Flop, repo: Flop.Repo, default_limit: 35 end - + defmodule TestProviderNested do use Flop, adapter_opts: [repo: Flop.Repo], default_limit: 35 end - + describe "ordering" do test "adds order_by to query if set" do pets = insert_list(20, :pet) @@ -166,7 +168,7 @@ defmodule Flop.Integration.FlopTest do ) == Enum.reverse(expected) end end - + describe "filtering" do property "applies equality filter" do check all pet_count <- integer(@pet_count_range), @@ -256,14 +258,14 @@ defmodule Flop.Integration.FlopTest do checkin_checkout() end end - + # test "applies empty filter" do # require Flop.Adapter.Ecto.Operators - + # field = :species - + # d1 = dynamic([r], is_nil(field(r, ^field)) == ^true); d2 = dynamic([r], Flop.Adapter.Ecto.Operators.empty(:other) == ^true) - + # assert where(Pet, ^d1) == where(Pet, ^d2) # end @@ -728,7 +730,7 @@ defmodule Flop.Integration.FlopTest do assert Flop.query(Pet, flop) == Pet end end - + describe "all/3" do test "returns all matching entries" do matching_pets = insert_list(6, :pet, age: 5) @@ -754,7 +756,7 @@ defmodule Flop.Integration.FlopTest do refute Flop.all(Pet, %Flop{}, query_opts: [prefix: "other_schema"]) == [] end end - + describe "count/3" do test "returns count of matching entries" do _matching_pets = insert_list(6, :pet, age: 5) @@ -838,7 +840,7 @@ defmodule Flop.Integration.FlopTest do assert Flop.count(q, flop) == 3 end end - + describe "meta/3" do test "returns the meta information for a query with limit/offset" do _matching_pets = insert_list(7, :pet, age: 5) @@ -1005,7 +1007,7 @@ defmodule Flop.Integration.FlopTest do assert opts[:for] == Pet end end - + describe "run/3" do test "returns data and meta data" do insert_list(3, :pet) @@ -1013,7 +1015,7 @@ defmodule Flop.Integration.FlopTest do assert {[%Pet{}], %Meta{}} = Flop.run(Pet, flop) end end - + describe "validate_and_run/3" do test "returns error if flop is invalid" do flop = %Flop{ @@ -1037,7 +1039,7 @@ defmodule Flop.Integration.FlopTest do assert {:ok, {[%Pet{}], %Meta{}}} = Flop.validate_and_run(Pet, flop) end end - + describe "validate_and_run!/3" do test "raises if flop is invalid" do assert_raise Flop.InvalidParamsError, fn -> @@ -1051,7 +1053,7 @@ defmodule Flop.Integration.FlopTest do assert {[%Pet{}], %Meta{}} = Flop.validate_and_run!(Pet, flop) end end - + describe "offset-based pagination" do test "applies limit to query" do insert_list(6, :pet) @@ -1096,7 +1098,7 @@ defmodule Flop.Integration.FlopTest do assert Repo.all(query) == Enum.slice(sorted_pets, 8..11) end end - + describe "cursor pagination" do property "querying cursor by cursor forward includes all items in order" do check all pets <- uniq_list_of_pets(length: 1..25), @@ -1719,7 +1721,7 @@ defmodule Flop.Integration.FlopTest do ) end end - + describe "__using__/1" do test "defines wrapper functions that pass default options" do insert_list(3, :pet) @@ -1742,7 +1744,7 @@ defmodule Flop.Integration.FlopTest do assert Keyword.get(opts, :backend) == TestProvider end end - + describe "__using__/1 with nested adapter options" do test "defines wrapper functions that pass default options" do insert_list(3, :pet) @@ -1765,4 +1767,4 @@ defmodule Flop.Integration.FlopTest do assert Keyword.get(opts, :backend) == TestProviderNested end end -end \ No newline at end of file +end diff --git a/integration_test/pg/all_test.exs b/integration_test/pg/all_test.exs index beb5cfcd..215fc306 100644 --- a/integration_test/pg/all_test.exs +++ b/integration_test/pg/all_test.exs @@ -1 +1 @@ -Code.require_file "../cases/flop_test.exs", __DIR__ \ No newline at end of file +Code.require_file("../cases/flop_test.exs", __DIR__) diff --git a/integration_test/pg/test_helper.exs b/integration_test/pg/test_helper.exs index 3f332519..6a0b70ba 100644 --- a/integration_test/pg/test_helper.exs +++ b/integration_test/pg/test_helper.exs @@ -23,10 +23,11 @@ defmodule Flop.Integration.Case do end end -{:ok, _} = Ecto.Adapters.Postgres.ensure_all_started(Flop.Repo.config(), :temporary) +{:ok, _} = + Ecto.Adapters.Postgres.ensure_all_started(Flop.Repo.config(), :temporary) # Load up the repository, start it, and run migrations -_ = Ecto.Adapters.Postgres.storage_down(Flop.Repo.config()) +_ = Ecto.Adapters.Postgres.storage_down(Flop.Repo.config()) :ok = Ecto.Adapters.Postgres.storage_up(Flop.Repo.config()) {:ok, _pid} = Flop.Repo.start_link() @@ -35,4 +36,4 @@ _ = Ecto.Adapters.Postgres.storage_down(Flop.Repo.config()) Ecto.Adapters.SQL.Sandbox.mode(Flop.Repo, :manual) {:ok, _} = Application.ensure_all_started(:ex_machina) -ExUnit.start() \ No newline at end of file +ExUnit.start() diff --git a/integration_test/sqlite/all_test.exs b/integration_test/sqlite/all_test.exs index beb5cfcd..215fc306 100644 --- a/integration_test/sqlite/all_test.exs +++ b/integration_test/sqlite/all_test.exs @@ -1 +1 @@ -Code.require_file "../cases/flop_test.exs", __DIR__ \ No newline at end of file +Code.require_file("../cases/flop_test.exs", __DIR__) diff --git a/integration_test/sqlite/migration.exs b/integration_test/sqlite/migration.exs index 5308cca5..49d469e6 100644 --- a/integration_test/sqlite/migration.exs +++ b/integration_test/sqlite/migration.exs @@ -3,35 +3,35 @@ defmodule Flop.Repo.SQLite.Migration do def change do create table(:owners) do - add :age, :integer - add :email, :string - add :name, :string - add :tags, {:array, :string} - add :attributes, :map - add :extra, {:map, :string} + add(:age, :integer) + add(:email, :string) + add(:name, :string) + add(:tags, {:array, :string}) + add(:attributes, :map) + add(:extra, {:map, :string}) end create table(:pets) do - add :age, :integer - add :family_name, :string - add :given_name, :string - add :name, :string - add :owner_id, references(:owners) - add :species, :string - add :mood, :string - add :tags, {:array, :string} + add(:age, :integer) + add(:family_name, :string) + add(:given_name, :string) + add(:name, :string) + add(:owner_id, references(:owners)) + add(:species, :string) + add(:mood, :string) + add(:tags, {:array, :string}) end create table(:fruits) do - add :family, :string - add :name, :string - add :attributes, :map - add :extra, {:map, :string} - add :owner_id, references(:owners) + add(:family, :string) + add(:name, :string) + add(:attributes, :map) + add(:extra, {:map, :string}) + add(:owner_id, references(:owners)) end - + create table(:walking_distances) do add(:trip, :distance) end end -end \ No newline at end of file +end diff --git a/integration_test/sqlite/test_helper.exs b/integration_test/sqlite/test_helper.exs index 7c7cd047..37102cea 100644 --- a/integration_test/sqlite/test_helper.exs +++ b/integration_test/sqlite/test_helper.exs @@ -15,18 +15,19 @@ end defmodule Flop.Integration.Case do use ExUnit.CaseTemplate - + setup do :ok = Ecto.Adapters.SQL.Sandbox.checkout(Flop.Repo) end end -Code.require_file "migration.exs", __DIR__ +Code.require_file("migration.exs", __DIR__) -{:ok, _} = Ecto.Adapters.SQLite3.ensure_all_started(Flop.Repo.config(), :temporary) +{:ok, _} = + Ecto.Adapters.SQLite3.ensure_all_started(Flop.Repo.config(), :temporary) # Load up the repository, start it, and run migrations -_ = Ecto.Adapters.SQLite3.storage_down(Flop.Repo.config()) +_ = Ecto.Adapters.SQLite3.storage_down(Flop.Repo.config()) :ok = Ecto.Adapters.SQLite3.storage_up(Flop.Repo.config()) {:ok, _pid} = Flop.Repo.start_link() @@ -34,4 +35,4 @@ _ = Ecto.Adapters.SQLite3.storage_down(Flop.Repo.config()) :ok = Ecto.Migrator.up(Flop.Repo, 0, Flop.Repo.SQLite.Migration, log: false) {:ok, _} = Application.ensure_all_started(:ex_machina) -ExUnit.start() \ No newline at end of file +ExUnit.start()