-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trigger_engine: added trigger_id and trigger_name to http events
Changed - send_simple_event - retrieve_trigger_configuration to integrate trigger_id and trigger_name inside payload - using exandra -- waiting for database project - implemented jwt + public/private key - wip group tests - squashed all failure - polishing - removed one_of_constant -> member_of - splitted tests - WIP device generator - completed device generator...but using opaque data (TODO change it) - basic datetime generator - WIP device generator - using Keyword.validate! - WIP insert into db, IPNET error - completed device WIP id doesn't match - completed base tests device FIX #692 Signed-off-by: Gabriele Ghio <[email protected]>
- Loading branch information
1 parent
20fa298
commit 7299862
Showing
24 changed files
with
1,456 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
apps/astarte_appengine_api/test/astarte_appengine_api/v2_device_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule Astarte.AppEngine.API.V2DeviceTest do | ||
use ExUnit.Case, async: true | ||
use ExUnitProperties | ||
use Astarte.Test.Cases.Device | ||
|
||
alias Ecto.Changeset | ||
alias StreamData | ||
alias Astarte.Core.Mapping | ||
alias Astarte.Core.Interface | ||
alias Astarte.AppEngine.API.Stats | ||
alias Astarte.AppEngine.API.Stats.DevicesStats | ||
alias Astarte.Test.Setups.Database, as: DatabaseSetup | ||
alias Astarte.Test.Setups.Interface, as: InterfaceSetup | ||
alias Astarte.Test.Generators.String, as: StringGenerator | ||
alias Astarte.Test.Generators.Interface, as: InterfaceGenerator | ||
alias Astarte.Test.Generators.Mapping, as: MappingGenerator | ||
alias Astarte.Test.Generators.Device, as: DeviceGenerator | ||
alias Astarte.Test.Helpers.Database, as: DatabaseHelper | ||
|
||
@moduletag :v2 | ||
@moduletag :device | ||
@moduletag interface_count: 10 | ||
@moduletag device_count: 10 | ||
|
||
describe "device generator" do | ||
property "validate device with pre-generated interfaces", %{interfaces: interfaces} do | ||
check all device <- DeviceGenerator.device(interfaces: interfaces) do | ||
:ok | ||
end | ||
end | ||
end | ||
|
||
describe "devices db" do | ||
test "validate insered devices", %{ | ||
cluster: cluster, | ||
realm: realm, | ||
devices: devices | ||
} do | ||
list = DatabaseHelper.select!(:device, cluster, realm, devices) | ||
|
||
f = fn l -> Enum.map(l, fn d -> d.id end) end | ||
devices_ids_a = f.(devices) | ||
devices_ids_b = f.(list) | ||
|
||
assert [] === devices_ids_a -- devices_ids_b | ||
assert [] === devices_ids_b -- devices_ids_a | ||
end | ||
end | ||
end |
171 changes: 171 additions & 0 deletions
171
apps/astarte_appengine_api/test/astarte_appengine_api/v2_group_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
defmodule Astarte.AppEngine.API.V2GroupTest do | ||
use ExUnit.Case, async: true | ||
use ExUnitProperties | ||
use Astarte.Test.Cases.Conn | ||
|
||
alias Astarte.Test.Setups.Database, as: DatabaseSetup | ||
alias Astarte.Test.Setups.Conn, as: ConnSetup | ||
alias Astarte.Test.Generators.Group, as: GroupGenerator | ||
alias Astarte.Test.Generators.Device, as: DeviceGenerator | ||
|
||
@moduletag :v2 | ||
@moduletag :group | ||
@moduletag interface_count: 10 | ||
@moduletag device_count: 100 | ||
|
||
describe "create" do | ||
property "wrong group name", %{auth_conn: auth_conn, realm: realm} do | ||
check all {{group_name, error}, devices} <- | ||
tuple({ | ||
bind(GroupGenerator.name(), fn name -> | ||
bind(integer(0..2), fn num -> | ||
constant( | ||
case num do | ||
0 -> {"", "can't be blank"} | ||
1 -> {"~" <> name, "is not valid"} | ||
2 -> {"@" <> name, "is not valid"} | ||
end | ||
) | ||
end) | ||
end), | ||
list_of(DeviceGenerator.encoded_id(), min_length: 0, max_length: 1) | ||
}) do | ||
params = %{ | ||
"group_name" => group_name, | ||
"devices" => devices | ||
} | ||
|
||
response = post(auth_conn, groups_path(auth_conn, :create, realm), data: params) | ||
assert [error] === json_response(response, 422)["errors"]["group_name"] | ||
end | ||
end | ||
|
||
property "devices list empty", %{auth_conn: auth_conn, realm: realm} do | ||
check all group_name <- GroupGenerator.name() do | ||
params = %{ | ||
"group_name" => group_name, | ||
"devices" => [] | ||
} | ||
|
||
response = post(auth_conn, groups_path(auth_conn, :create, realm), data: params) | ||
|
||
assert ["should have at least 1 item(s)"] === | ||
json_response(response, 422)["errors"]["devices"] | ||
end | ||
end | ||
|
||
property "device does not exist", %{auth_conn: auth_conn, realm: realm} do | ||
check all group_name <- GroupGenerator.name(), | ||
devices <- list_of(DeviceGenerator.encoded_id(), min_length: 1) do | ||
params = %{ | ||
"group_name" => group_name, | ||
"devices" => devices | ||
} | ||
|
||
response = post(auth_conn, groups_path(auth_conn, :create, realm), data: params) | ||
|
||
assert ["must exist (#{Enum.at(devices, 0)} not found)"] === | ||
json_response(response, 422)["errors"]["devices"] | ||
end | ||
end | ||
end | ||
|
||
# describe "devices checks" do | ||
# # TODO devices | ||
# # setup [ | ||
# # {DeviceSetup, :init}, | ||
# # {DeviceSetup, :setup} | ||
# # ] | ||
|
||
# property "rejects empty devices", %{auth_conn: auth_conn, realm: realm} do | ||
# check all group_name <- GroupGenerator.group_name() do | ||
# params = %{ | ||
# "group_name" => group_name, | ||
# "devices" => [] | ||
# } | ||
|
||
# response = post(auth_conn, groups_path(auth_conn, :create, realm), data: params) | ||
|
||
# assert ["should have at least 1 item(s)"] === | ||
# json_response(response, 422)["errors"]["devices"] | ||
# end | ||
# end | ||
# end | ||
|
||
# describe "create" do | ||
# | ||
|
||
# test "doesn't create group if a device doesn't exist", %{conn: conn} do | ||
# params = %{ | ||
# "group_name" => @group_name, | ||
# "devices" => [ | ||
# "2uL21mYBQsWVik8declWQQ" | ||
# | @group_devices | ||
# ] | ||
# } | ||
|
||
# create_conn = post(conn, groups_path(conn, :create, @realm), data: params) | ||
|
||
# assert json_response(create_conn, 422)["errors"]["devices"] != nil | ||
|
||
# show_conn = get(conn, groups_path(conn, :show, @realm, @group_name)) | ||
|
||
# assert json_response(show_conn, 404) | ||
# end | ||
|
||
# test "creates the group with valid parameters", %{conn: conn} do | ||
# params = %{ | ||
# "group_name" => @group_name, | ||
# "devices" => @group_devices | ||
# } | ||
|
||
# create_conn = post(conn, groups_path(conn, :create, @realm), data: params) | ||
|
||
# assert json_response(create_conn, 201)["data"] == params | ||
|
||
# show_conn = get(conn, groups_path(conn, :show, @realm, @group_name)) | ||
|
||
# assert json_response(show_conn, 200)["data"]["group_name"] == @group_name | ||
|
||
# for device <- @group_devices do | ||
# {:ok, %DeviceStatus{groups: groups}} = Device.get_device_status!(@realm, device) | ||
# assert groups == [@group_name] | ||
# end | ||
# end | ||
|
||
# test "rejects an already existing group", %{conn: conn} do | ||
# params = %{ | ||
# "group_name" => @group_name, | ||
# "devices" => @group_devices | ||
# } | ||
|
||
# create_conn = post(conn, groups_path(conn, :create, @realm), data: params) | ||
|
||
# assert json_response(create_conn, 201)["data"] == params | ||
|
||
# create_again_conn = post(conn, groups_path(conn, :create, @realm), data: params) | ||
|
||
# assert json_response(create_again_conn, 409)["errors"] != nil | ||
# end | ||
|
||
# @tag issue: 904 | ||
# property "creates the group with / in group name", %{conn: conn} do | ||
# check all group_name <- GroupTestGenerator.group_name() do | ||
# params = %{ | ||
# "group_name" => group_name, | ||
# "devices" => @group_devices | ||
# } | ||
|
||
# create_conn = post(conn, groups_path(conn, :create, @realm), data: params) | ||
|
||
# assert json_response(create_conn, 201)["data"] == params, | ||
# "Failed to create group #{group_name}" | ||
|
||
# show_conn = get(conn, groups_path(conn, :show, @realm, group_name)) | ||
|
||
# assert json_response(show_conn, 200)["data"]["group_name"] == group_name, | ||
# "Failed post/get same group_name #{group_name}" | ||
# end | ||
# end | ||
# end | ||
end |
50 changes: 50 additions & 0 deletions
50
apps/astarte_appengine_api/test/astarte_appengine_api/v2_interface_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule Astarte.AppEngine.API.V2InterfaceTest do | ||
use ExUnit.Case, async: true | ||
use ExUnitProperties | ||
use Astarte.Test.Cases.Interface | ||
|
||
alias Ecto.Changeset | ||
alias StreamData | ||
alias Astarte.Core.Mapping | ||
alias Astarte.Core.Interface | ||
alias Astarte.AppEngine.API.Stats | ||
alias Astarte.AppEngine.API.Stats.DevicesStats | ||
alias Astarte.Test.Setups.Database, as: DatabaseSetup | ||
alias Astarte.Test.Setups.Interface, as: InterfaceSetup | ||
alias Astarte.Test.Generators.String, as: StringGenerator | ||
alias Astarte.Test.Generators.Interface, as: InterfaceGenerator | ||
alias Astarte.Test.Generators.Mapping, as: MappingGenerator | ||
alias Astarte.Test.Generators.Device, as: DeviceGenerator | ||
alias Astarte.Test.Helpers.Database, as: DatabaseHelper | ||
|
||
@moduletag :v2 | ||
@moduletag :interface | ||
@moduletag interface_count: 10 | ||
|
||
describe "interface generator" do | ||
@tag timeout: :infinity | ||
property "validate interface" do | ||
check all interface <- InterfaceGenerator.interface() do | ||
%Changeset{valid?: valid, errors: errors} = Interface.changeset(interface) | ||
|
||
assert valid, "Invalid interface: " <> (errors |> Enum.join(", ")) | ||
end | ||
end | ||
end | ||
|
||
describe "interfaces db" do | ||
test "validate insered interfaces names", %{ | ||
cluster: cluster, | ||
realm: realm, | ||
interfaces: interfaces | ||
} do | ||
list = DatabaseHelper.select!(:interface, cluster, realm, interfaces) | ||
f = fn l -> Enum.map(l, fn i -> i.name end) end | ||
interfaces_names_a = f.(interfaces) | ||
interfaces_names_b = f.(list) | ||
|
||
assert [] === interfaces_names_a -- interfaces_names_b | ||
assert [] === interfaces_names_b -- interfaces_names_a | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule Astarte.Test.Cases.Conn do | ||
use ExUnit.CaseTemplate | ||
use Astarte.Test.Cases.Database | ||
|
||
using do | ||
quote do | ||
import Plug.Conn | ||
import Phoenix.ConnTest | ||
import Astarte.AppEngine.APIWeb.Router.Helpers | ||
|
||
# The default endpoint for testing | ||
@endpoint Astarte.AppEngine.APIWeb.Endpoint | ||
end | ||
end | ||
|
||
alias Astarte.Test.Setups.Conn, as: ConnSetup | ||
|
||
setup_all [ | ||
{ConnSetup, :create_conn}, | ||
{ConnSetup, :jwt}, | ||
{ConnSetup, :auth_conn} | ||
] | ||
end |
Oops, something went wrong.