Skip to content

Commit

Permalink
RM test: move to Xandra
Browse files Browse the repository at this point in the history
Replace CQEx with Xandra in
database_test_helper, queries_test, engine_test.

Signed-off-by: Arnaldo Cesco <[email protected]>
  • Loading branch information
Annopaolo committed Aug 2, 2023
1 parent fa55277 commit b6966d9
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,20 +618,14 @@ defmodule Astarte.RealmManagement.EngineTest do
@test_realm_name "autotestrealm"

setup do
with {:ok, client} <- DatabaseTestHelper.connect_to_test_database() do
DatabaseTestHelper.seed_test_data(client)
end
DatabaseTestHelper.seed_test_data()
end

setup_all do
with {:ok, client} <- DatabaseTestHelper.connect_to_test_database() do
DatabaseTestHelper.create_test_keyspace(client)
end
DatabaseTestHelper.create_test_keyspace()

on_exit(fn ->
with {:ok, client} <- DatabaseTestHelper.connect_to_test_database() do
DatabaseTestHelper.drop_test_keyspace(client)
end
DatabaseTestHelper.drop_test_keyspace()
end)
end

Expand Down Expand Up @@ -677,7 +671,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.list_interface_versions(
"autotestrealm",
"com.ispirata.Hemera.DeviceLog.Configuration"
) == {:ok, [[major_version: 1, minor_version: 0]]}
) == {:ok, [%{major_version: 1, minor_version: 0}]}

assert Engine.list_interface_versions(
"autotestrealm",
Expand Down Expand Up @@ -753,9 +747,7 @@ defmodule Astarte.RealmManagement.EngineTest do
unpack_source({:ok, @test_draft_interface_a_0})

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.Draft") ==
{:ok, [[major_version: 0, minor_version: 2]]}

{:ok, client} = Database.connect(realm: "autotestrealm")
{:ok, [%{major_version: 0, minor_version: 2}]}

d = :crypto.strong_rand_bytes(16)

Expand All @@ -767,10 +759,9 @@ defmodule Astarte.RealmManagement.EngineTest do
)

p1 = "/filterRules/0/TEST/value"
DatabaseTestHelper.seed_properties_test_value(client, d, "com.ispirata.Draft", 0, e1, p1)
DatabaseTestHelper.seed_properties_test_value(d, "com.ispirata.Draft", 0, e1, p1)

assert DatabaseTestHelper.count_interface_properties_for_device(
client,
d,
"com.ispirata.Draft",
0
Expand All @@ -779,7 +770,6 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.delete_interface("autotestrealm", "com.ispirata.Draft", 0) == :ok

assert DatabaseTestHelper.count_interface_properties_for_device(
client,
d,
"com.ispirata.Draft",
0
Expand All @@ -801,7 +791,7 @@ defmodule Astarte.RealmManagement.EngineTest do
unpack_source({:ok, @test_draft_interface_a_0})

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.Draft") ==
{:ok, [[major_version: 0, minor_version: 2]]}
{:ok, [%{major_version: 0, minor_version: 2}]}
end

test "install object aggregated interface" do
Expand All @@ -810,7 +800,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ObjectAggregation"]}

assert Engine.list_interface_versions("autotestrealm", "com.ObjectAggregation") ==
{:ok, [[major_version: 0, minor_version: 3]]}
{:ok, [%{major_version: 0, minor_version: 3}]}

assert Engine.delete_interface("autotestrealm", "com.ObjectAggregation", 0) == :ok

Expand All @@ -826,7 +816,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ObjectAggregation"]}

assert Engine.list_interface_versions("autotestrealm", "com.ObjectAggregation") ==
{:ok, [[major_version: 0, minor_version: 3]]}
{:ok, [%{major_version: 0, minor_version: 3}]}

assert Engine.delete_interface("autotestrealm", "com.ObjectAggregation", 0) == :ok
end
Expand All @@ -837,16 +827,13 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}

{:ok, client} = Database.connect(realm: "autotestrealm")
{:ok, [%{major_version: 0, minor_version: 10}]}

d = :crypto.strong_rand_bytes(16)
e1 = CQLUtils.endpoint_id("com.ispirata.TestDatastream", 0, "/%{sensorId}/realValues")
p1 = "/0/realValues"

DatabaseTestHelper.seed_datastream_test_data(
client,
d,
"com.ispirata.TestDatastream",
0,
Expand All @@ -858,7 +845,6 @@ defmodule Astarte.RealmManagement.EngineTest do
p2 = "/0/integerValues"

DatabaseTestHelper.seed_datastream_test_data(
client,
d,
"com.ispirata.TestDatastream",
0,
Expand All @@ -869,7 +855,6 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.delete_interface("autotestrealm", "com.ispirata.TestDatastream", 0) == :ok

assert DatabaseTestHelper.count_rows_for_datastream(
client,
d,
"com.ispirata.TestDatastream",
0,
Expand All @@ -878,7 +863,6 @@ defmodule Astarte.RealmManagement.EngineTest do
) == 0

assert DatabaseTestHelper.count_rows_for_datastream(
client,
d,
"com.ispirata.TestDatastream",
0,
Expand All @@ -897,7 +881,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_c_1) == :ok

Expand All @@ -908,7 +892,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 15]]}
{:ok, [%{major_version: 0, minor_version: 15}]}
end

test "update explicit timestamp, doc, description, expiry and retention for individual datastream interface" do
Expand All @@ -917,7 +901,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["org.astarte-platform.Values"]}

assert Engine.list_interface_versions("autotestrealm", "org.astarte-platform.Values") ==
{:ok, [[major_version: 1, minor_version: 0]]}
{:ok, [%{major_version: 1, minor_version: 0}]}

assert Engine.update_interface("autotestrealm", @test_interface_d_1) == :ok

Expand All @@ -927,7 +911,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert {:ok, ^updated_interface} = unpack_source({:ok, @test_interface_d_1})

assert Engine.list_interface_versions("autotestrealm", "org.astarte-platform.Values") ==
{:ok, [[major_version: 1, minor_version: 1]]}
{:ok, [%{major_version: 1, minor_version: 1}]}

assert Engine.update_interface("autotestrealm", @test_interface_d_incompatible_change) ==
{:error, :incompatible_endpoint_change}
Expand All @@ -942,7 +926,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ObjectAggregation"]}

assert Engine.list_interface_versions("autotestrealm", "com.ObjectAggregation") ==
{:ok, [[major_version: 0, minor_version: 3]]}
{:ok, [%{major_version: 0, minor_version: 3}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_b_1) == :ok

Expand All @@ -952,7 +936,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ObjectAggregation"]}

assert Engine.list_interface_versions("autotestrealm", "com.ObjectAggregation") ==
{:ok, [[major_version: 0, minor_version: 4]]}
{:ok, [%{major_version: 0, minor_version: 4}]}

assert Engine.delete_interface("autotestrealm", "com.ObjectAggregation", 0) == :ok

Expand All @@ -966,7 +950,7 @@ defmodule Astarte.RealmManagement.EngineTest do
{:ok, ["com.autotest.AggregateValuesUpdate"]}

assert Engine.list_interface_versions("autotestrealm", "com.autotest.AggregateValuesUpdate") ==
{:ok, [[major_version: 1, minor_version: 0]]}
{:ok, [%{major_version: 1, minor_version: 0}]}

assert Engine.update_interface("autotestrealm", @test_interface_e_1) == :ok

Expand All @@ -978,7 +962,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert {:ok, ^updated_interface} = unpack_source({:ok, @test_interface_e_1})

assert Engine.list_interface_versions("autotestrealm", "com.autotest.AggregateValuesUpdate") ==
{:ok, [[major_version: 1, minor_version: 1]]}
{:ok, [%{major_version: 1, minor_version: 1}]}

assert Engine.update_interface("autotestrealm", @test_interface_e_incompatible_change) ==
{:error, :invalid_interface_document}
Expand All @@ -994,7 +978,7 @@ defmodule Astarte.RealmManagement.EngineTest do
"autotestrealm",
"com.autotest.AggregateValuesUpdateAndAdd"
) ==
{:ok, [[major_version: 1, minor_version: 0]]}
{:ok, [%{major_version: 1, minor_version: 0}]}

assert Engine.update_interface("autotestrealm", @test_interface_f_1) == :ok

Expand All @@ -1009,7 +993,7 @@ defmodule Astarte.RealmManagement.EngineTest do
"autotestrealm",
"com.autotest.AggregateValuesUpdateAndAdd"
) ==
{:ok, [[major_version: 1, minor_version: 1]]}
{:ok, [%{major_version: 1, minor_version: 1}]}
end

test "fail update missing interface" do
Expand All @@ -1026,15 +1010,15 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_c_wrong_update) ==
{:error, :missing_endpoints}

assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_c_1) == :ok

Expand All @@ -1048,7 +1032,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 15]]}
{:ok, [%{major_version: 0, minor_version: 15}]}
end

test "fail on interface type change" do
Expand All @@ -1057,7 +1041,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_c_invalid_change) ==
{:error, :invalid_update}
Expand All @@ -1069,7 +1053,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}
end

test "fail on mapping incompatible change" do
Expand All @@ -1078,7 +1062,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_c_incompatible_change) ==
{:error, :incompatible_endpoint_change}
Expand All @@ -1090,7 +1074,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.get_interfaces_list("autotestrealm") == {:ok, ["com.ispirata.TestDatastream"]}

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}
end

test "fail on interface downgrade" do
Expand All @@ -1101,7 +1085,7 @@ defmodule Astarte.RealmManagement.EngineTest do
) == unpack_source({:ok, @test_draft_interface_c_0})

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 10]]}
{:ok, [%{major_version: 0, minor_version: 10}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_c_1) == :ok

Expand All @@ -1110,7 +1094,7 @@ defmodule Astarte.RealmManagement.EngineTest do
) == unpack_source({:ok, @test_draft_interface_c_1})

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 15]]}
{:ok, [%{major_version: 0, minor_version: 15}]}

assert Engine.update_interface("autotestrealm", @test_draft_interface_c_downgrade) ==
{:error, :downgrade_not_allowed}
Expand All @@ -1120,7 +1104,7 @@ defmodule Astarte.RealmManagement.EngineTest do
) == unpack_source({:ok, @test_draft_interface_c_1})

assert Engine.list_interface_versions("autotestrealm", "com.ispirata.TestDatastream") ==
{:ok, [[major_version: 0, minor_version: 15]]}
{:ok, [%{major_version: 0, minor_version: 15}]}
end

test "get JWT public key PEM with existing realm" do
Expand Down Expand Up @@ -1417,7 +1401,7 @@ defmodule Astarte.RealmManagement.EngineTest do
assert Engine.delete_trigger_policy("autotestrealm", "aname") == :ok
end

test "trigger with non existant policy fails" do
test "trigger with non existent policy fails" do
trigger = %{
realm_name: "autotestrealm",
name: "test_trigger",
Expand Down
Loading

0 comments on commit b6966d9

Please sign in to comment.