From 5c6838583992b362fc9812cda4944c64f940ddb6 Mon Sep 17 00:00:00 2001 From: Francesco Noacco Date: Tue, 1 Oct 2024 15:57:53 +0200 Subject: [PATCH] refactor!: remove xandra cluster and utils so as not to rewrite the tests, for now we still register the cluster used by Exandra under the same name. --- lib/astarte_data_access.ex | 7 ------- test/device_test.exs | 4 ++-- test/support/database_test_helper.exs | 26 +++++++++++++------------- test/test_helper.exs | 15 ++++++++++++++- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/astarte_data_access.ex b/lib/astarte_data_access.ex index 6e760b4..188cfdd 100644 --- a/lib/astarte_data_access.ex +++ b/lib/astarte_data_access.ex @@ -28,14 +28,7 @@ defmodule Astarte.DataAccess do def init(init_arg) do xandra_options = Keyword.fetch!(init_arg, :xandra_options) - xandra_cluster_options = - xandra_options - |> Keyword.put(:name, :astarte_data_access_xandra) - # TODO move to string keys - |> Keyword.put(:atom_keys, true) - children = [ - {Xandra.Cluster, xandra_cluster_options}, {Astarte.DataAccess.Repo, xandra_options} ] diff --git a/test/device_test.exs b/test/device_test.exs index a9893f9..fe4778e 100644 --- a/test/device_test.exs +++ b/test/device_test.exs @@ -83,8 +83,8 @@ defmodule Astarte.DataAccess.Device.XandraTest do Xandra.Cluster.prepare!(:astarte_data_access_xandra, insert_empty_introspection_stmt) Xandra.Cluster.execute!(:astarte_data_access_xandra, prepared, %{ - device_id: device_id, - empty_introspection: %{} + "device_id" => device_id, + "empty_introspection" => %{} }) assert Device.interface_version( diff --git a/test/support/database_test_helper.exs b/test/support/database_test_helper.exs index 5c8ba58..39544d3 100644 --- a/test/support/database_test_helper.exs +++ b/test/support/database_test_helper.exs @@ -426,9 +426,9 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do device_id = Base.url_decode64!(encoded_device_id, padding: false) insert_device_query_params = %{ - device_id: device_id, - aliases: aliases, - total_received_bytes: total_received_bytes + "device_id" => device_id, + "aliases" => aliases, + "total_received_bytes" => total_received_bytes } insert_device_query_prp = Xandra.prepare!(conn, @insert_device_statement) @@ -437,8 +437,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do for {_key, device_alias} <- aliases || %{} do insert_alias_query_params = %{ - device_id: device_id, - alias: device_alias + "device_id" => device_id, + "alias" => device_alias } alias_query_prepared = Xandra.prepare!(conn, @insert_alias_statement) @@ -448,11 +448,11 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do end insert_into_interface_0_params = %{ - automaton_accepting_states: + "automaton_accepting_states" => Base.decode64!( "g3QAAAAFYQNtAAAAEIAeEDVf33Bpjm4/0nkmmathBG0AAAAQjrtis2DBS6JBcp3e3YCcn2EFbQAAABBP5QNKPZuZ7H7DsjcWMD0zYQdtAAAAEOb3NjHv/B1+rVLT86O65QthCG0AAAAQKyxj3bvZVzVtSo5W9QTt2g==" ), - automaton_transitions: + "automaton_transitions" => Base.decode64!( "g3QAAAAIaAJhAG0AAAAKbGNkQ29tbWFuZGEFaAJhAG0AAAAEdGltZWEGaAJhAG0AAAAMd2Vla1NjaGVkdWxlYQFoAmEBbQAAAABhAmgCYQJtAAAABXN0YXJ0YQNoAmECbQAAAARzdG9wYQRoAmEGbQAAAARmcm9tYQdoAmEGbQAAAAJ0b2EI" ) @@ -463,11 +463,11 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do Xandra.execute!(conn, insert_into_interface_0_prepared, insert_into_interface_0_params) insert_into_interface_1_params = %{ - automaton_accepting_states: + "automaton_accepting_states" => Base.decode64!( "g3QAAAAFYQJtAAAAEHUBDhsZnu783TXSVLDiCSRhBW0AAAAQOQfUHVvKMp2eUUzqKlSpmmEGbQAAABB6pEwRInNH2eYkSuAp3t6qYQdtAAAAEO/5V88D397tl4SocI49jLlhCG0AAAAQNGyA5MqZYnSB9nscG+WVIQ==" ), - automaton_transitions: + "automaton_transitions" => Base.decode64!( "g3QAAAAIaAJhAG0AAAAAYQFoAmEAbQAAAANmb29hA2gCYQFtAAAABXZhbHVlYQJoAmEDbQAAAABhBGgCYQRtAAAACWJsb2JWYWx1ZWEGaAJhBG0AAAAJbG9uZ1ZhbHVlYQdoAmEEbQAAAAtzdHJpbmdWYWx1ZWEFaAJhBG0AAAAOdGltZXN0YW1wVmFsdWVhCA==" ) @@ -480,8 +480,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do Xandra.execute!(conn, @insert_into_interface_2, %{}) insert_into_interface_3_params = %{ - automaton_accepting_states: Base.decode64!("g3QAAAABYQNtAAAAEOPZVKNVUNqw17mW3O0hiYc="), - automaton_transitions: + "automaton_accepting_states" => Base.decode64!("g3QAAAABYQNtAAAAEOPZVKNVUNqw17mW3O0hiYc="), + "automaton_transitions" => Base.decode64!("g3QAAAADaAJhAG0AAAAAYQFoAmEBbQAAAABhAmgCYQJtAAAABWNvbG9yYQM=") } @@ -490,8 +490,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do Xandra.execute!(conn, insert_into_interface_3_prepared, insert_into_interface_3_params) insert_into_interface_4_params = %{ - automaton_accepting_states: Base.decode64!("g3QAAAABYQNtAAAAEGZjaujopxRZWiHuQLZfzfQ="), - automaton_transitions: + "automaton_accepting_states" => Base.decode64!("g3QAAAABYQNtAAAAEGZjaujopxRZWiHuQLZfzfQ="), + "automaton_transitions" => Base.decode64!( "g3QAAAADaAJhAG0AAAADbmV3YQFoAmEBbQAAAAlpbnRlcmZhY2VhAmgCYQJtAAAABXZhbHVlYQM=" ) diff --git a/test/test_helper.exs b/test/test_helper.exs index d4ec925..764a49a 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,9 +1,22 @@ +alias Astarte.DataAccess.Config + ExUnit.start() children = [ - {Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()} + {Astarte.DataAccess, xandra_options: Config.xandra_options!()} ] Supervisor.start_link(children, strategy: :one_for_one) +# Register the Xandra cluster process so that it can be used in tests +# Yes they both have id 'Astarte.DataAccess.Repo' +Astarte.DataAccess +|> Supervisor.which_children() +# Astarte.DataAccess' child +|> Enum.find_value(fn {id, pid, _, _} -> id == Astarte.DataAccess.Repo && pid end) +|> Supervisor.which_children() +# Astarte.DataAccess.Repo's child +|> Enum.find_value(fn {id, pid, _, _} -> id == Astarte.DataAccess.Repo && pid end) +|> Process.register(:astarte_data_access_xandra) + Code.require_file("support/database_test_helper.exs", __DIR__)