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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class UpdateConfig
/// be updated simultaneously.
/// </summary>
[YamlMember(Alias = "parallelism")]
public string? Parallelism { get; set; }
public int? Parallelism { get; set; }

/// <summary>
/// Represents the delay between each update operation for a service node in a swarm configuration.
Expand All @@ -30,10 +30,11 @@ public sealed class UpdateConfig
public string? Delay { get; set; }

/// <summary>
/// Indicates whether the update process should stop and fail upon encountering an error.
/// Gets or sets the action to take when an update fails.
/// Valid values are "continue", "rollback", or "pause" (default).
/// </summary>
[YamlMember(Alias = "failure_action")]
public bool? FailOnError { get; set; }
public string? FailureAction { get; set; }

/// <summary>
/// Gets or sets the duration or interval for monitoring the progress of an update.
Expand Down
96 changes: 96 additions & 0 deletions tests/Aspire.Hosting.Docker.Tests/UpdateConfigTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.Docker.Resources;
using Aspire.Hosting.Docker.Resources.ComposeNodes;
using Aspire.Hosting.Docker.Resources.ServiceNodes.Swarm;

namespace Aspire.Hosting.Docker.Tests;

public class UpdateConfigTests
{
[Fact]
public void UpdateConfig_SerializesParallelismAsInteger()
{
// Arrange
var updateConfig = new UpdateConfig
{
Parallelism = 2
};

var composeFile = new ComposeFile
{
Services = new Dictionary<string, Service>
{
["test-service"] = new Service
{
Name = "test-service",
Image = "nginx",
Deploy = new Deploy
{
UpdateConfig = updateConfig
}
}
}
};

// Act
var yaml = composeFile.ToYaml();

// Assert - should serialize as integer (correct)
Assert.Contains("parallelism: 2", yaml);
Assert.DoesNotContain("parallelism: \"2\"", yaml);
}

[Theory]
[InlineData("continue")]
[InlineData("rollback")]
[InlineData("pause")]
public void UpdateConfig_AcceptsValidFailureActionValues(string failureAction)
{
// Arrange & Act
var updateConfig = new UpdateConfig
{
FailureAction = failureAction
};

// Assert - no exception should be thrown
Assert.Equal(failureAction, updateConfig.FailureAction);
}

[Fact]
public void UpdateConfig_NullValuesOmittedFromYaml()
{
// Arrange - Only set some properties
var updateConfig = new UpdateConfig
{
Parallelism = 3, // Set to verify not all are null
FailureAction = null, // Should be omitted
Delay = null // Should be omitted
};

var composeFile = new ComposeFile
{
Services = new Dictionary<string, Service>
{
["test-service"] = new Service
{
Name = "test-service",
Image = "nginx",
Deploy = new Deploy
{
UpdateConfig = updateConfig
}
}
}
};

// Act
var yaml = composeFile.ToYaml();

// Assert - null values should be omitted
Assert.Contains("parallelism: 3", yaml);
Assert.DoesNotContain("failure_action:", yaml);
Assert.DoesNotContain("delay:", yaml);
}
}
Loading