-
Notifications
You must be signed in to change notification settings - Fork 117
Send git commit information as service message from ArgoCD steps #1749
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
530b7a3
Add ArgoCD deployment service message reporting
sathvikkumar-octo 03008bc
Extract duplicate convention constructors into helper methods
sathvikkumar-octo b296dc6
Test cleanup
sathvikkumar-octo b1049e7
Simplify ProcessApplicationResult construction in conventions
sathvikkumar-octo cb21a96
Remove dead code
sathvikkumar-octo 10b510a
Set all ProcessApplicationResult properties in constructor
sathvikkumar-octo 21ca568
Add test cases to conventions test
sathvikkumar-octo 4918391
PR feedback
sathvikkumar-octo 0a18b0a
rename message
sathvikkumar-octo 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
120 changes: 120 additions & 0 deletions
120
source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs
This file contains hidden or 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,120 @@ | ||
| using System.Collections.Generic; | ||
| using Calamari.ArgoCD; | ||
| using Calamari.ArgoCD.Models; | ||
| using Calamari.Testing.Helpers; | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Calamari.Tests.ArgoCD | ||
| { | ||
| [TestFixture] | ||
| public class ArgoCDFilesUpdatedReporterTests | ||
| { | ||
| [Test] | ||
| public void ReportDeployments_WithNoUpdatedApplications_WritesNoServiceMessages() | ||
| { | ||
| var log = new InMemoryLog(); | ||
| var reporter = new ArgoCDFilesUpdatedReporter(log); | ||
|
|
||
| var applicationResults = new List<ProcessApplicationResult> | ||
| { | ||
| new("gateway1", new ApplicationName("app1"), 2, 2, [], [], []) | ||
| }; | ||
|
|
||
| reporter.ReportDeployments(applicationResults); | ||
|
|
||
| var messages = log.ServiceMessages; | ||
| messages.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ReportDeployments_WithSingleUpdatedApplication_WritesOneServiceMessage() | ||
| { | ||
| var log = new InMemoryLog(); | ||
| var reporter = new ArgoCDFilesUpdatedReporter(log); | ||
|
|
||
| var applicationResults = new List<ProcessApplicationResult> | ||
| { | ||
| new("gateway1", new ApplicationName("app1"), 2, 2, [new UpdatedSourceDetail("abc123", 0, [], [])], [], []) | ||
| }; | ||
|
|
||
| reporter.ReportDeployments(applicationResults); | ||
|
|
||
| log.ServiceMessages.Should().ContainSingle().Which.Should().BeEquivalentTo(new | ||
| { | ||
| Name = "argocd-files-updated", | ||
| Properties = new Dictionary<string, string> | ||
| { | ||
| ["gatewayId"] = "gateway1", | ||
| ["applicationName"] = "app1", | ||
| ["sources"] = "[{\"CommitSha\":\"abc123\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServiceMessages() | ||
| { | ||
| var log = new InMemoryLog(); | ||
| var reporter = new ArgoCDFilesUpdatedReporter(log); | ||
|
|
||
| var applicationResults = new List<ProcessApplicationResult> | ||
| { | ||
| new("gateway1", new ApplicationName("app1"), 2, 2, [new UpdatedSourceDetail("abc123", 0, [], [])], [], []), | ||
| new("gateway2", new ApplicationName("app2"), 1, 1, [new UpdatedSourceDetail("def456", 0, [], [])], [], []) | ||
| }; | ||
|
|
||
| reporter.ReportDeployments(applicationResults); | ||
|
|
||
| log.ServiceMessages.Should().BeEquivalentTo([ | ||
| new | ||
| { | ||
| Name = "argocd-files-updated", | ||
| Properties = new Dictionary<string, string> | ||
| { | ||
| ["gatewayId"] = "gateway1", | ||
| ["applicationName"] = "app1", | ||
| ["sources"] = "[{\"CommitSha\":\"abc123\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" | ||
| } | ||
| }, | ||
| new | ||
| { | ||
| Name = "argocd-files-updated", | ||
| Properties = new Dictionary<string, string> | ||
| { | ||
| ["gatewayId"] = "gateway2", | ||
| ["applicationName"] = "app2", | ||
| ["sources"] = "[{\"CommitSha\":\"def456\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" | ||
| } | ||
| } | ||
| ]); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOnlyUpdatedMessages() | ||
| { | ||
| var log = new InMemoryLog(); | ||
| var reporter = new ArgoCDFilesUpdatedReporter(log); | ||
|
|
||
| var applicationResults = new List<ProcessApplicationResult> | ||
| { | ||
| new("gateway1", new ApplicationName("app1"), 2, 2, [], [], []), | ||
| new("gateway2", new ApplicationName("app2"), 1, 1, [new UpdatedSourceDetail("abc123", 0, [], [])], [], []), | ||
| new("gateway3", new ApplicationName("app3"), 1, 1, [], [], []) | ||
| }; | ||
|
|
||
| reporter.ReportDeployments(applicationResults); | ||
|
|
||
| log.ServiceMessages.Should().ContainSingle().Which.Should().BeEquivalentTo(new | ||
| { | ||
| Name = "argocd-files-updated", | ||
| Properties = new Dictionary<string, string> | ||
| { | ||
| ["gatewayId"] = "gateway2", | ||
| ["applicationName"] = "app2", | ||
| ["sources"] = "[{\"CommitSha\":\"abc123\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.