-
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 FIX #692 Signed-off-by: Gabriele Ghio <[email protected]>
- Loading branch information
1 parent
20fa298
commit 4412eeb
Showing
19 changed files
with
1,136 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
156 changes: 156 additions & 0 deletions
156
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,156 @@ | ||
defmodule Astarte.AppEngine.API.V2GroupTest do | ||
use ExUnit.Case, async: true | ||
use ExUnitProperties | ||
use Astarte.Test.Cases.Database | ||
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 | ||
|
||
describe "create" do | ||
property "failed", %{auth_conn: auth_conn, realm: realm} do | ||
invalid_group_name_generator = | ||
gen all name <- GroupGenerator.name(), | ||
choice <- integer(0..2) do | ||
case choice do | ||
0 -> "" | ||
1 -> "~" <> name | ||
2 -> "@" <> name | ||
end | ||
end | ||
|
||
group_results_generator = | ||
gen all name <- one_of([GroupGenerator.name(), invalid_group_name_generator]), | ||
devices <- list_of(DeviceGenerator.encoded_id(), min_length: 0, max_length: 1) do | ||
{name, devices, | ||
cond do | ||
"" === name -> | ||
{"group_name", "can't be blank"} | ||
|
||
String.first(name) in ["@", "~"] -> | ||
{"group_name", "is not valid"} | ||
|
||
length(devices) === 0 -> | ||
{"devices", "should have at least 1 item(s)"} | ||
|
||
true -> | ||
{"devices", "must exist (#{Enum.at(devices, 0)} not found)"} | ||
end} | ||
end | ||
|
||
check all {group_name, devices, {field, error}} <- group_results_generator 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"][field] | ||
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 |
52 changes: 52 additions & 0 deletions
52
apps/astarte_appengine_api/test/astarte_appengine_api/v2_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,52 @@ | ||
defmodule Astarte.AppEngine.API.V2Test do | ||
use ExUnit.Case, async: true | ||
use ExUnitProperties | ||
use Astarte.Test.Cases.Database | ||
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 | ||
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 | ||
setup [ | ||
{InterfaceSetup, :init}, | ||
{InterfaceSetup, :setup} | ||
] | ||
|
||
@tag interface_count: 100 | ||
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,22 @@ | ||
defmodule Astarte.Test.Cases.Conn do | ||
use ExUnit.CaseTemplate | ||
|
||
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 |
17 changes: 17 additions & 0 deletions
17
apps/astarte_appengine_api/test/support_v2/cases/database.ex
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,17 @@ | ||
defmodule Astarte.Test.Cases.Database do | ||
use ExUnit.CaseTemplate | ||
|
||
using do | ||
quote do | ||
end | ||
end | ||
|
||
alias Astarte.Test.Setups.Database, as: DatabaseSetup | ||
|
||
setup_all [ | ||
{DatabaseSetup, :connect}, | ||
{DatabaseSetup, :realm}, | ||
{DatabaseSetup, :setup}, | ||
{DatabaseSetup, :setup_auth} | ||
] | ||
end |
Empty file.
24 changes: 24 additions & 0 deletions
24
apps/astarte_appengine_api/test/support_v2/generators/device.ex
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,24 @@ | ||
defmodule Astarte.Test.Generators.Device do | ||
use ExUnitProperties | ||
|
||
def id() do | ||
gen all seq <- binary(length: 16) do | ||
<<u0::48, _::4, u1::12, _::2, u2::62>> = seq | ||
<<u0::48, 4::4, u1::12, 2::2, u2::62>> | ||
end | ||
end | ||
|
||
def encoded_id() do | ||
gen all id <- id() do | ||
Base.url_encode64(id, padding: false) | ||
end | ||
end | ||
|
||
def device() do | ||
gen all id <- id() do | ||
%{ | ||
id: id | ||
} | ||
end | ||
end | ||
end |
59 changes: 59 additions & 0 deletions
59
apps/astarte_appengine_api/test/support_v2/generators/entites_OLD.ex
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,59 @@ | ||
defmodule Astarte.Test.Generators.Entities_OLD do | ||
use ExUnitProperties | ||
|
||
def domain() do | ||
gen all first <- string([?a..?z], length: 3), | ||
second <- string([?a..?z, ?A..?Z], min_length: 1, max_length: 10), | ||
third <- string([?a..?z, ?A..?Z], min_length: 1, max_length: 10) do | ||
first <> "." <> second <> "." <> third | ||
end | ||
end | ||
|
||
def interface() do | ||
gen all domain <- domain(), | ||
enabled <- boolean() do | ||
{domain, enabled} | ||
end | ||
end | ||
|
||
def interface_value() do | ||
gen all interface <- interface(), | ||
value <- integer(1..100_100) do | ||
{interface, value} | ||
end | ||
end | ||
|
||
def interfaces() do | ||
gen all interface_value <- list_of(interface_value()), | ||
num <- integer(0..20) do | ||
Enum.take(interface_value, num) |> Map.new() | ||
end | ||
end | ||
|
||
def options do | ||
optional_map(%{ | ||
display_name: string(:alphanumeric), | ||
serial: string(?0..?9, min_length: 1, max_length: 10) | ||
}) | ||
end | ||
|
||
def attributes do | ||
fixed_map(%{ | ||
attribute_key: string(:alphanumeric) | ||
}) | ||
end | ||
|
||
def device() do | ||
gen all id <- string(:alphanumeric, length: 22), | ||
value <- integer(0..8_000_000), | ||
interfaces <- one_of([nil, interfaces()]), | ||
options <- one_of([nil, options()]), | ||
attributes <- attributes() do | ||
{id, value, interfaces, options, attributes} | ||
end | ||
end | ||
|
||
def devices() do | ||
list_of(device()) | ||
end | ||
end |
Oops, something went wrong.