|
| 1 | +using System.Collections.Generic; |
| 2 | +using Calamari.ArgoCD; |
| 3 | +using Calamari.ArgoCD.Models; |
| 4 | +using Calamari.Testing.Helpers; |
| 5 | +using FluentAssertions; |
| 6 | +using NUnit.Framework; |
| 7 | + |
| 8 | +namespace Calamari.Tests.ArgoCD |
| 9 | +{ |
| 10 | + [TestFixture] |
| 11 | + public class ArgoCDFilesUpdatedReporterTests |
| 12 | + { |
| 13 | + [Test] |
| 14 | + public void ReportDeployments_WithNoUpdatedApplications_WritesNoServiceMessages() |
| 15 | + { |
| 16 | + var log = new InMemoryLog(); |
| 17 | + var reporter = new ArgoCDFilesUpdatedReporter(log); |
| 18 | + |
| 19 | + var applicationResults = new List<ProcessApplicationResult> |
| 20 | + { |
| 21 | + new("gateway1", new ApplicationName("app1"), 2, 2, [], [], []) |
| 22 | + }; |
| 23 | + |
| 24 | + reporter.ReportDeployments(applicationResults); |
| 25 | + |
| 26 | + var messages = log.ServiceMessages; |
| 27 | + messages.Should().BeEmpty(); |
| 28 | + } |
| 29 | + |
| 30 | + [Test] |
| 31 | + public void ReportDeployments_WithSingleUpdatedApplication_WritesOneServiceMessage() |
| 32 | + { |
| 33 | + var log = new InMemoryLog(); |
| 34 | + var reporter = new ArgoCDFilesUpdatedReporter(log); |
| 35 | + |
| 36 | + var applicationResults = new List<ProcessApplicationResult> |
| 37 | + { |
| 38 | + new("gateway1", new ApplicationName("app1"), 2, 2, [new UpdatedSourceDetail("abc123", 0, [], [])], [], []) |
| 39 | + }; |
| 40 | + |
| 41 | + reporter.ReportDeployments(applicationResults); |
| 42 | + |
| 43 | + log.ServiceMessages.Should().ContainSingle().Which.Should().BeEquivalentTo(new |
| 44 | + { |
| 45 | + Name = "argocd-files-updated", |
| 46 | + Properties = new Dictionary<string, string> |
| 47 | + { |
| 48 | + ["gatewayId"] = "gateway1", |
| 49 | + ["applicationName"] = "app1", |
| 50 | + ["sources"] = "[{\"CommitSha\":\"abc123\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" |
| 51 | + } |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + [Test] |
| 56 | + public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServiceMessages() |
| 57 | + { |
| 58 | + var log = new InMemoryLog(); |
| 59 | + var reporter = new ArgoCDFilesUpdatedReporter(log); |
| 60 | + |
| 61 | + var applicationResults = new List<ProcessApplicationResult> |
| 62 | + { |
| 63 | + new("gateway1", new ApplicationName("app1"), 2, 2, [new UpdatedSourceDetail("abc123", 0, [], [])], [], []), |
| 64 | + new("gateway2", new ApplicationName("app2"), 1, 1, [new UpdatedSourceDetail("def456", 0, [], [])], [], []) |
| 65 | + }; |
| 66 | + |
| 67 | + reporter.ReportDeployments(applicationResults); |
| 68 | + |
| 69 | + log.ServiceMessages.Should().BeEquivalentTo([ |
| 70 | + new |
| 71 | + { |
| 72 | + Name = "argocd-files-updated", |
| 73 | + Properties = new Dictionary<string, string> |
| 74 | + { |
| 75 | + ["gatewayId"] = "gateway1", |
| 76 | + ["applicationName"] = "app1", |
| 77 | + ["sources"] = "[{\"CommitSha\":\"abc123\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" |
| 78 | + } |
| 79 | + }, |
| 80 | + new |
| 81 | + { |
| 82 | + Name = "argocd-files-updated", |
| 83 | + Properties = new Dictionary<string, string> |
| 84 | + { |
| 85 | + ["gatewayId"] = "gateway2", |
| 86 | + ["applicationName"] = "app2", |
| 87 | + ["sources"] = "[{\"CommitSha\":\"def456\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" |
| 88 | + } |
| 89 | + } |
| 90 | + ]); |
| 91 | + } |
| 92 | + |
| 93 | + [Test] |
| 94 | + public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOnlyUpdatedMessages() |
| 95 | + { |
| 96 | + var log = new InMemoryLog(); |
| 97 | + var reporter = new ArgoCDFilesUpdatedReporter(log); |
| 98 | + |
| 99 | + var applicationResults = new List<ProcessApplicationResult> |
| 100 | + { |
| 101 | + new("gateway1", new ApplicationName("app1"), 2, 2, [], [], []), |
| 102 | + new("gateway2", new ApplicationName("app2"), 1, 1, [new UpdatedSourceDetail("abc123", 0, [], [])], [], []), |
| 103 | + new("gateway3", new ApplicationName("app3"), 1, 1, [], [], []) |
| 104 | + }; |
| 105 | + |
| 106 | + reporter.ReportDeployments(applicationResults); |
| 107 | + |
| 108 | + log.ServiceMessages.Should().ContainSingle().Which.Should().BeEquivalentTo(new |
| 109 | + { |
| 110 | + Name = "argocd-files-updated", |
| 111 | + Properties = new Dictionary<string, string> |
| 112 | + { |
| 113 | + ["gatewayId"] = "gateway2", |
| 114 | + ["applicationName"] = "app2", |
| 115 | + ["sources"] = "[{\"CommitSha\":\"abc123\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}]" |
| 116 | + } |
| 117 | + }); |
| 118 | + } |
| 119 | + } |
| 120 | +} |
0 commit comments