-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize an ExecutionCompleted json cloud event #11
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e039fc
Make Execution Result json encodable
nelsonkopliku 25d12f1
Added test for serializing ExecutionCompletedV1 event
nelsonkopliku bea9264
Updated Mapper to support serializing outgoing events to cloud events
nelsonkopliku 9e2b0e5
Make the AMQP adapter publish a json CloudEvent
nelsonkopliku 087c8d1
Merge EventRegistry in Mapper
nelsonkopliku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,53 @@ | ||
{ | ||
"data": { | ||
"check_results": [ | ||
{ | ||
"agents_check_results": [ | ||
{ | ||
"agent_id": "agent_1", | ||
"expectation_evaluations": [ | ||
{ | ||
"name": "timeout", | ||
"return_value": true, | ||
"type": "expect" | ||
} | ||
], | ||
"facts": { | ||
"corosync_token_timeout": 30000 | ||
} | ||
}, | ||
{ | ||
"agent_id": "agent_2", | ||
"expectation_evaluations": [ | ||
{ | ||
"name": "timeout", | ||
"return_value": true, | ||
"type": "expect" | ||
} | ||
], | ||
"facts": { | ||
"corosync_token_timeout": 30000 | ||
} | ||
} | ||
], | ||
"check_id": "expect_check", | ||
"expectation_results": [ | ||
{ | ||
"name": "timeout", | ||
"result": true, | ||
"type": "expect" | ||
} | ||
], | ||
"result": "passing" | ||
} | ||
], | ||
"execution_id": "d9955082-42c9-4835-b53a-3a4d3b2e4a9c", | ||
"group_id": "421af233-dbb2-4328-907e-8b355b00bde8", | ||
"result": "passing" | ||
}, | ||
"datacontenttype": "application/json", | ||
"id": "d9955082-42c9-4835-b53a-3a4d3b2e4a9c", | ||
"source": "https://github.com/trento-project/wanda", | ||
"specversion": "1.0", | ||
"type": "trento.checks.v1.ExecutionCompleted" | ||
} |
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,43 @@ | ||
defmodule Wanda.MapperTest do | ||
@moduledoc false | ||
|
||
use ExUnit.Case | ||
|
||
import Wanda.Factory | ||
|
||
alias Wanda.Messaging.Mapper | ||
|
||
alias Wanda.Support.Messaging.DummyEvent | ||
|
||
describe "serializing outgoing events" do | ||
test "should produce an error for unsupported events" do | ||
assert {:error, :unsupported_event} = Mapper.to_json(%DummyEvent{}) | ||
end | ||
|
||
test "should produce a serialized ExecutionCompletedV1 cloud event" do | ||
execution_result = | ||
build(:execution_result, | ||
execution_id: "d9955082-42c9-4835-b53a-3a4d3b2e4a9c", | ||
group_id: "421af233-dbb2-4328-907e-8b355b00bde8" | ||
) | ||
|
||
expected_cloud_event = | ||
File.read!("test/fixtures/events/execution_completed_succesfully.json") | ||
|> String.replace(["\r", "\n", " "], "") | ||
|
||
assert expected_cloud_event == Mapper.to_json(execution_result) | ||
end | ||
|
||
test "should produce an ExecutionCompletedV1 with a valid event data, as per the schema" do | ||
execution_result = build(:execution_result) | ||
event_type = "trento.checks.v1.ExecutionCompleted" | ||
|
||
%{"data" => event_data, "type" => ^event_type} = | ||
execution_result | ||
|> Mapper.to_json() | ||
|> Jason.decode!() | ||
|
||
assert :ok = Wanda.JsonSchema.validate(event_type, event_data) | ||
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
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,7 @@ | ||
defmodule Wanda.Support.Messaging.DummyEvent do | ||
@moduledoc false | ||
|
||
defstruct [ | ||
:some_property | ||
] | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to return
:ok
or:error
here, because conceptually nobody shouldn't be passing unsupported events to this function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I fully understand.
What do you mean? Could you elaborate a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caller of this function should know if an event is supported or not, hence the tagged tuple is not needed here IMHO