Skip to content

Commit

Permalink
add integration_test folder to formatter config, format
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Sep 10, 2024
1 parent f8f070a commit 56b4b26
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 56 deletions.
5 changes: 4 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -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]
]
50 changes: 26 additions & 24 deletions integration_test/cases/flop_test.exs
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
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

Check failure on line 7 in integration_test/cases/flop_test.exs

View workflow job for this annotation

GitHub Actions / OTP 27 / Elixir 1.17

doctest module Flop (7) (Flop.Integration.FlopTest)

Check failure on line 7 in integration_test/cases/flop_test.exs

View workflow job for this annotation

GitHub Actions / OTP 26 / Elixir 1.15

doctest module Flop (7) (Flop.Integration.FlopTest)

Check failure on line 7 in integration_test/cases/flop_test.exs

View workflow job for this annotation

GitHub Actions / OTP 26 / Elixir 1.17

doctest module Flop (7) (Flop.Integration.FlopTest)

Check failure on line 7 in integration_test/cases/flop_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.15

doctest module Flop (7) (Flop.Integration.FlopTest)

Check failure on line 7 in integration_test/cases/flop_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.16

doctest module Flop (7) (Flop.Integration.FlopTest)

Check failure on line 7 in integration_test/cases/flop_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.14

doctest module Flop (7) (Flop.Integration.FlopTest)

Check failure on line 7 in integration_test/cases/flop_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.14

doctest module Flop (7) (Flop.Integration.FlopTest)

import Ecto.Query
import Flop.Factory
import Flop.Generators
import Flop.TestUtil

alias __MODULE__.TestProvider
alias Ecto.Query.QueryExpr
alias Flop.Filter
alias Flop.Meta
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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1005,15 +1007,15 @@ 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)
flop = %Flop{page_size: 2, page: 2}
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{
Expand All @@ -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 ->
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -1765,4 +1767,4 @@ defmodule Flop.Integration.FlopTest do
assert Keyword.get(opts, :backend) == TestProviderNested
end
end
end
end
2 changes: 1 addition & 1 deletion integration_test/pg/all_test.exs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Code.require_file "../cases/flop_test.exs", __DIR__
Code.require_file("../cases/flop_test.exs", __DIR__)
7 changes: 4 additions & 3 deletions integration_test/pg/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
ExUnit.start()
2 changes: 1 addition & 1 deletion integration_test/sqlite/all_test.exs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Code.require_file "../cases/flop_test.exs", __DIR__
Code.require_file("../cases/flop_test.exs", __DIR__)
42 changes: 21 additions & 21 deletions integration_test/sqlite/migration.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
11 changes: 6 additions & 5 deletions integration_test/sqlite/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ 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()

:ok = Ecto.Migrator.up(Flop.Repo, 0, Flop.Repo.SQLite.Migration, log: false)

{:ok, _} = Application.ensure_all_started(:ex_machina)
ExUnit.start()
ExUnit.start()

0 comments on commit 56b4b26

Please sign in to comment.