Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 135 additions & 95 deletions source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs

Large diffs are not rendered by default.

253 changes: 239 additions & 14 deletions source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Calamari.Tests.ArgoCD.Commands.Conventions
class ArgoCDApplicationBuilder
{
string name = "My App";
string @namespace = "argocd";
Dictionary<string, string> annotations = new Dictionary<string, string>();
readonly List<ApplicationSource> applicationSources = new List<ApplicationSource>();
readonly List<string> applicationSourceTypes = new List<string>();
Expand All @@ -17,6 +18,12 @@ public ArgoCDApplicationBuilder WithName(string value)
return this;
}

public ArgoCDApplicationBuilder WithNamespace(string value)
{
@namespace = value;
return this;
}

public ArgoCDApplicationBuilder WithAnnotations(Dictionary<string, string> value)
{
annotations = value;
Expand Down Expand Up @@ -47,6 +54,7 @@ public Application Build()
Metadata = new Metadata()
{
Name = name,
Namespace = @namespace,
Annotations = annotations
},
Spec = new ApplicationSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void Init()
Metadata = new Metadata()
{
Name = "App1",
Namespace = "argocd",
Annotations = new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -174,7 +175,7 @@ public void HelmSource_NoPath_DontUpdate()
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -828,7 +829,7 @@ public void HelmSourceWithHelmConfigurationAndImplicitValuesFile_IncludeValuesFi
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -911,7 +912,7 @@ public void HelmSourceWithHelmConfigurationAndNoImplicitValuesFile_ExcludeValues
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -995,7 +996,7 @@ public void HelmSourceWithHelmConfigurationIncludesImplicitValuesFile_IncludeVal
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -1081,7 +1082,7 @@ public void HelmSourceWithImplicitValuesFile_Update()
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -1162,7 +1163,7 @@ public void RefSourceWithHelmImageMatches_Update()
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("ref-source"))] = ProjectSlug,
Expand Down Expand Up @@ -1293,7 +1294,7 @@ public void RefSourceWithHelmImageMatchesAndPath_IgnoresFilesUnderPath()
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("ref-source"))] = ProjectSlug,
Expand Down Expand Up @@ -1448,7 +1449,7 @@ public void CanUpdateRefSourceUsingStepBasedVariables()
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("ref-source"))] = ProjectSlug,
Expand Down Expand Up @@ -1598,7 +1599,7 @@ public void CanUpdateHelmSourceUsingStepBasedVariables()
originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo);

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("helm-source"))] = ProjectSlug,
Expand Down Expand Up @@ -1817,7 +1818,7 @@ void SetupRefSourceAppManifest(
}

var app = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(annotations)
.WithSource(new ApplicationSource
{
Expand Down Expand Up @@ -1900,10 +1901,10 @@ void AssertOutputVariables(bool updated = true, string matchingApplicationTotalS
serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be(GatewayId);
serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be(updated ? OriginUrl : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be(updated ? updatedImages.ToString() : "0");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("App1");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("argocd/App1");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be(matchingApplicationTotalSourceCounts);
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be(matchingApplicationMatchingSourceCounts);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "App1" : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "argocd/App1" : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be(updated ? "1" : string.Empty);

if (updated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void Init()
customPropertiesLoader.Load<ArgoCDCustomPropertiesDto>().Returns(argoCdCustomPropertiesDto);

var argoCdApplicationFromYaml = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -1052,7 +1052,7 @@ void OverrideApplicationSourceType(string sourceType, string path = "")
{
argoCdApplicationManifestParser.ParseManifest(Arg.Any<string>())
.Returns(new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -1123,7 +1123,7 @@ public void MultiSource_OneSourceUpdated_OtherAlreadyAtTarget_BothTracked()

argoCdApplicationManifestParser.ParseManifest(Arg.Any<string>())
.Returns(new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("source0"))] = ProjectSlug,
Expand Down Expand Up @@ -1182,7 +1182,7 @@ public void MultiSource_BothSourcesAlreadyAtTarget_BothTrackedWithNullCommitSha(

argoCdApplicationManifestParser.ParseManifest(Arg.Any<string>())
.Returns(new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("source0"))] = ProjectSlug,
Expand Down Expand Up @@ -1243,7 +1243,7 @@ public void MultiSource_OutOfScopeSource_IsNotTracked()

argoCdApplicationManifestParser.ParseManifest(Arg.Any<string>())
.Returns(new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>
{
// source0 is annotated for a different project — out of scope for this deployment
Expand Down Expand Up @@ -1302,10 +1302,10 @@ void AssertOutputVariables(bool updated = true, string matchingApplicationTotalS
serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be(GatewayId);
serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be(updated ? OriginUrl : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be(updated ? "1" : "0");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("App1");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("argocd/App1");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be(matchingApplicationTotalSourceCounts);
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("1");
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "App1" : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "argocd/App1" : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be(updated ? "1" : string.Empty);

if (updated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void Init()
customPropertiesLoader.Load<ArgoCDCustomPropertiesDto>().Returns(argoCdCustomPropertiesDto);

var argoCdApplicationFromYaml = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -232,7 +232,7 @@ public void CanTemplateFilesIntoAHelmSource()
runningDeployment.StagingDirectory = WorkingDirectory;

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -293,7 +293,7 @@ public void CanUpdateReferenceSource()
runningDeployment.StagingDirectory = WorkingDirectory;

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("refSourceName"))] = ProjectSlug,
Expand Down Expand Up @@ -362,7 +362,7 @@ public void WillNotUpdateAReferenceSourceWhichHasAPath()
runningDeployment.StagingDirectory = WorkingDirectory;

var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("refSourceName"))] = ProjectSlug,
Expand Down Expand Up @@ -518,7 +518,7 @@ public void CanTemplateFilesIntoAnUnknownSource()
runningDeployment.StagingDirectory = WorkingDirectory;

var argoCDAppWithUnknownSource = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -560,7 +560,7 @@ public void PathAnnotationOverridesTheOutputPath()
// Arrange - create app with a path-override in the annotation
var overriddenSubPath = Path.Combine("sub1", "sub2");
var argoCdApplicationFromYaml = new ArgoCDApplicationBuilder()
.WithName("App1")
.WithName("App1").WithNamespace("argocd")
.WithAnnotations(new Dictionary<string, string>()
{
[ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug,
Expand Down Expand Up @@ -652,10 +652,10 @@ void AssertOutputVariables(bool updated = true, string matchingApplicationTotalS
var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable");
serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be(GatewayId);
serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be(updated ? OriginUrl : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("App1");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("argocd/App1");
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be(matchingApplicationTotalSourceCounts);
serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("1");
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "App1" : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "argocd/App1" : string.Empty);
serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be(updated ? "1" : string.Empty);

if (updated)
Expand Down
Loading