From 7eb7e20c710cb55ec2483a891a20349d139efcf1 Mon Sep 17 00:00:00 2001 From: Arnaldo Cesco Date: Thu, 30 Nov 2023 18:18:37 +0100 Subject: [PATCH] IncomingIntrospectionEvent holds a map IncomingIntrospectionEvent holds now a map interface-name -> {major, minor}. Keep the old plain introspection string as a deprecated field. Signed-off-by: Arnaldo Cesco --- CHANGELOG.md | 2 ++ .../incoming_introspection_event.pb.ex | 28 +++++++++++++++++-- .../incoming_introspection_event.proto | 8 +++++- .../triggers/simple_events_test.exs | 27 ++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 723866a..28262e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Bump Elixir to 1.15.7. - Bump Erlang/OTP to 26.1. +- IncomingIntrospectionEvent holds now a interface-name -> {major, minor} map + instead of the plain introspection string. ## [1.1.1] - 2023-10-03 ### Fixed diff --git a/lib/astarte_core/triggers/simple_events/incoming_introspection_event.pb.ex b/lib/astarte_core/triggers/simple_events/incoming_introspection_event.pb.ex index 9e31183..abf313d 100644 --- a/lib/astarte_core/triggers/simple_events/incoming_introspection_event.pb.ex +++ b/lib/astarte_core/triggers/simple_events/incoming_introspection_event.pb.ex @@ -1,9 +1,31 @@ +defmodule Astarte.Core.Triggers.SimpleEvents.InterfaceVersion do + @moduledoc false + + use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" + + field :major, 1, type: :int32 + field :minor, 2, type: :int32 +end + +defmodule Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent.IntrospectionMapEntry do + @moduledoc false + + use Protobuf, map: true, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" + + field :key, 1, type: :string + field :value, 2, type: Astarte.Core.Triggers.SimpleEvents.InterfaceVersion +end + defmodule Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent do @moduledoc false - use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3 + use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" - def fully_qualified_name, do: "IncomingIntrospectionEvent" + field :introspection, 1, proto3_optional: true, type: :string, deprecated: true - field :introspection, 1, proto3_optional: true, type: :string + field :introspection_map, 2, + repeated: true, + type: Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent.IntrospectionMapEntry, + json_name: "introspectionMap", + map: true end diff --git a/lib/astarte_core/triggers/simple_events/incoming_introspection_event.proto b/lib/astarte_core/triggers/simple_events/incoming_introspection_event.proto index f4d2a14..be55ebc 100644 --- a/lib/astarte_core/triggers/simple_events/incoming_introspection_event.proto +++ b/lib/astarte_core/triggers/simple_events/incoming_introspection_event.proto @@ -18,6 +18,12 @@ syntax = "proto3"; +message InterfaceVersion { + int32 major = 1; + int32 minor = 2; +} + message IncomingIntrospectionEvent { - optional string introspection = 1; + optional string introspection = 1 [deprecated = true]; + map introspection_map = 2; } diff --git a/test/astarte_core/triggers/simple_events_test.exs b/test/astarte_core/triggers/simple_events_test.exs index db9c823..e85a02e 100644 --- a/test/astarte_core/triggers/simple_events_test.exs +++ b/test/astarte_core/triggers/simple_events_test.exs @@ -412,4 +412,31 @@ defmodule Astarte.Core.SimpleEventsTest do assert ValueStoredEvent.decode(serialized_event) == event end end + + describe "IncomingIntrospectionEvent" do + alias Astarte.Core.Triggers.SimpleEvents.IncomingIntrospectionEvent + + test "is correctly serialized when payload is a string" do + introspection_string = "com.an.Interface:1:0;com.another.Interface:0:1" + + event = %IncomingIntrospectionEvent{introspection: introspection_string} + + assert ^event = + IncomingIntrospectionEvent.encode(event) |> IncomingIntrospectionEvent.decode() + end + + test "is correctly serialized when payload is a map" do + alias Astarte.Core.Triggers.SimpleEvents.InterfaceVersion + + introspection_map = %{ + "com.an.Interface" => %InterfaceVersion{major: 1, minor: 0}, + "com.another.Interface" => %InterfaceVersion{major: 0, minor: 1} + } + + event = %IncomingIntrospectionEvent{introspection_map: introspection_map} + + assert ^event = + IncomingIntrospectionEvent.encode(event) |> IncomingIntrospectionEvent.decode() + end + end end