Skip to content

Commit da0a962

Browse files
incoming_introspection_event + tests
Signed-off-by: Gabriele Ghio <gabriele.ghio@secomind.com>
1 parent bdaec9e commit da0a962

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# This file is part of Astarte.
3+
#
4+
# Copyright 2025 SECO Mind Srl
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
defmodule Astarte.Core.Generators.Triggers.SimpleEvents.IncomingIntrospectionEvent do
20+
@moduledoc """
21+
This module provides generators for Astarte Trigger Simple Event IncomingIntrospectionEvent struct.
22+
"""
23+
use ExUnitProperties
24+
25+
import Astarte.Generators.Utilities.ParamsGen
26+
27+
alias Astarte.Core.Interface
28+
alias Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent
29+
alias Astarte.Core.Triggers.SimpleEvents.InterfaceVersion
30+
31+
alias Astarte.Core.Generators.Interface, as: InterfaceGenerator
32+
33+
@spec incoming_introspection_event() :: StreamData.t(IncomingIntrospectionEvent.t())
34+
@spec incoming_introspection_event(keyword :: keyword()) ::
35+
StreamData.t(IncomingIntrospectionEvent.t())
36+
def incoming_introspection_event(params \\ []) do
37+
params gen all interfaces <- InterfaceGenerator.interface() |> list_of(max_length: 10),
38+
params: params do
39+
introspection_map =
40+
interfaces
41+
|> Enum.map(fn %Interface{
42+
name: name,
43+
major_version: major_version,
44+
minor_version: minor_version
45+
} ->
46+
{name, major_version, minor_version}
47+
end)
48+
|> Map.new(fn {name, major_version, minor_version} ->
49+
{name,
50+
%InterfaceVersion{
51+
major: major_version,
52+
minor: minor_version
53+
}}
54+
end)
55+
56+
%IncomingIntrospectionEvent{
57+
introspection_map: introspection_map
58+
}
59+
end
60+
end
61+
end
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# This file is part of Astarte.
3+
#
4+
# Copyright 2025 SECO Mind Srl
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
defmodule Astarte.Core.Generators.Triggers.SimpleEvents.IncomingIntrospectionEventTest do
20+
use ExUnit.Case, async: true
21+
use ExUnitProperties
22+
23+
alias Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent
24+
25+
alias Astarte.Core.Generators.Interface, as: InterfaceGenerator
26+
27+
alias Astarte.Core.Generators.Triggers.SimpleEvents.IncomingIntrospectionEvent,
28+
as: IncomingIntrospectionEventGenerator
29+
30+
@moduletag :trigger
31+
@moduletag :simple_event
32+
@moduletag :incoming_introspection_event
33+
34+
@doc false
35+
describe "triggers incoming_introspection_event generator" do
36+
@describetag :success
37+
@describetag :ut
38+
property "generates valid incoming_introspection_event" do
39+
check all incoming_introspection_event <-
40+
IncomingIntrospectionEventGenerator.incoming_introspection_event() do
41+
assert %IncomingIntrospectionEvent{} = incoming_introspection_event
42+
end
43+
end
44+
45+
property "checking fields (keys, versions) in incoming_introspection_event generated from interfaces (list)" do
46+
check all interfaces <- InterfaceGenerator.interface() |> list_of(max_length: 10),
47+
incoming_introspection_event <-
48+
IncomingIntrospectionEventGenerator.incoming_introspection_event(
49+
interfaces: interfaces
50+
) do
51+
assert %IncomingIntrospectionEvent{} = incoming_introspection_event
52+
end
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)