chore: update project structure with contracts and services for CaddyManager, including configuration and Docker integration
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m16s
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m16s
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
using CaddyManager.Configurations.Caddy;
|
||||
|
||||
namespace CaddyManager.Tests.Configurations.Caddy;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for CaddyServiceConfigurations
|
||||
/// </summary>
|
||||
public class CaddyServiceConfigurationsTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests that the CaddyServiceConfigurations constructor initializes with the correct default values.
|
||||
/// Setup: Creates a new CaddyServiceConfigurations instance using the default constructor.
|
||||
/// Expectation: The ConfigDir property should be set to "/config" by default, ensuring proper initialization for Caddy service configuration management without requiring explicit configuration.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Constructor_InitializesWithDefaultValues()
|
||||
{
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations();
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be("/config");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property can be set and retrieved correctly with a custom path value.
|
||||
/// Setup: Creates a CaddyServiceConfigurations instance and sets ConfigDir to a custom path "/custom/caddy/config".
|
||||
/// Expectation: The property should store and return the exact value provided, ensuring proper configuration path management for Caddy service operations in custom deployment scenarios.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConfigDir_CanBeSetAndRetrieved()
|
||||
{
|
||||
// Arrange
|
||||
var customPath = "/custom/caddy/config";
|
||||
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations
|
||||
{
|
||||
ConfigDir = customPath
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be(customPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property correctly handles various valid path formats across different operating systems.
|
||||
/// Setup: Uses parameterized test data including Unix paths, Windows paths, and common Caddy configuration directories.
|
||||
/// Expectation: The property should accept and store any path format, supporting cross-platform deployment scenarios and different Caddy installation configurations.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("/config")]
|
||||
[InlineData("/var/lib/caddy")]
|
||||
[InlineData("/home/user/caddy-configs")]
|
||||
[InlineData("C:\\Caddy\\Config")]
|
||||
[InlineData("/opt/caddy/configurations")]
|
||||
public void ConfigDir_WithVariousPaths_SetsCorrectly(string path)
|
||||
{
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations
|
||||
{
|
||||
ConfigDir = path
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property can be set to an empty string value.
|
||||
/// Setup: Creates a CaddyServiceConfigurations instance and explicitly sets ConfigDir to an empty string.
|
||||
/// Expectation: The property should accept and store the empty string, allowing for scenarios where configuration directory might be cleared or reset programmatically.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConfigDir_WithEmptyString_SetsCorrectly()
|
||||
{
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations
|
||||
{
|
||||
ConfigDir = ""
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be("");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property can be set to a null value.
|
||||
/// Setup: Creates a CaddyServiceConfigurations instance and explicitly sets ConfigDir to null.
|
||||
/// Expectation: The property should accept and store null values, supporting scenarios where configuration directory is undefined or needs to be cleared.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConfigDir_WithNullValue_SetsCorrectly()
|
||||
{
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations
|
||||
{
|
||||
ConfigDir = null!
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().BeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property can be modified after the object has been created and initialized.
|
||||
/// Setup: Creates a CaddyServiceConfigurations instance with default values, then changes ConfigDir to a new path.
|
||||
/// Expectation: The property should be mutable and accept the new value, enabling runtime reconfiguration of Caddy service paths for dynamic deployment scenarios.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConfigDir_CanBeModifiedAfterCreation()
|
||||
{
|
||||
// Arrange
|
||||
var config = new CaddyServiceConfigurations();
|
||||
var newPath = "/new/config/path";
|
||||
|
||||
// Act
|
||||
config.ConfigDir = newPath;
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be(newPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the static Caddy constant has the correct string value.
|
||||
/// Setup: Accesses the static CaddyServiceConfigurations.Caddy constant.
|
||||
/// Expectation: The constant should return "Caddy", providing a consistent identifier for the Caddy service throughout the application for configuration and service management purposes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Constant_Caddy_HasCorrectValue()
|
||||
{
|
||||
// Assert
|
||||
CaddyServiceConfigurations.Caddy.Should().Be("Caddy");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property accepts various string values including whitespace and special characters.
|
||||
/// Setup: Uses parameterized test data with whitespace characters, paths containing spaces, and paths with special characters.
|
||||
/// Expectation: The property should accept all string values without validation restrictions, ensuring flexibility for diverse file system naming conventions and edge cases in Caddy configuration paths.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(" ")]
|
||||
[InlineData("\t")]
|
||||
[InlineData("\n")]
|
||||
[InlineData("path with spaces")]
|
||||
[InlineData("path/with/special/chars!@#$%")]
|
||||
public void ConfigDir_WithVariousStringValues_AcceptsAll(string path)
|
||||
{
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations
|
||||
{
|
||||
ConfigDir = path
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the default ConfigDir value meets all expected criteria for a valid configuration directory.
|
||||
/// Setup: Creates a CaddyServiceConfigurations instance using the default constructor.
|
||||
/// Expectation: The default ConfigDir should be "/config", not null, and not empty, ensuring a reliable starting point for Caddy service configuration management.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DefaultValue_IsCorrect()
|
||||
{
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations();
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be("/config");
|
||||
config.ConfigDir.Should().NotBeNull();
|
||||
config.ConfigDir.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property correctly handles relative path values.
|
||||
/// Setup: Creates a CaddyServiceConfigurations instance and sets ConfigDir to a relative path "./config".
|
||||
/// Expectation: The property should accept and store relative paths, supporting deployment scenarios where Caddy configuration is relative to the application's working directory.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConfigDir_WithRelativePath_SetsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var relativePath = "./config";
|
||||
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations
|
||||
{
|
||||
ConfigDir = relativePath
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be(relativePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the ConfigDir property can handle very long path values without truncation or errors.
|
||||
/// Setup: Creates a CaddyServiceConfigurations instance and sets ConfigDir to an extremely long path string.
|
||||
/// Expectation: The property should store and return the complete long path, ensuring support for deeply nested directory structures that might be used in complex Caddy deployment scenarios.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConfigDir_WithLongPath_SetsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var longPath = "/very/long/path/to/caddy/configuration/directory/that/might/be/used/in/some/scenarios";
|
||||
|
||||
// Act
|
||||
var config = new CaddyServiceConfigurations
|
||||
{
|
||||
ConfigDir = longPath
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.ConfigDir.Should().Be(longPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that multiple CaddyServiceConfigurations instances maintain independent ConfigDir values.
|
||||
/// Setup: Creates two separate CaddyServiceConfigurations instances with different ConfigDir values.
|
||||
/// Expectation: Each instance should maintain its own ConfigDir value independently, ensuring proper isolation when managing multiple Caddy service configurations simultaneously.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void MultipleInstances_HaveIndependentValues()
|
||||
{
|
||||
// Arrange
|
||||
var config1 = new CaddyServiceConfigurations { ConfigDir = "/path1" };
|
||||
var config2 = new CaddyServiceConfigurations { ConfigDir = "/path2" };
|
||||
|
||||
// Act & Assert
|
||||
config1.ConfigDir.Should().Be("/path1");
|
||||
config2.ConfigDir.Should().Be("/path2");
|
||||
config1.ConfigDir.Should().NotBe(config2.ConfigDir);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
using CaddyManager.Configurations.Docker;
|
||||
|
||||
namespace CaddyManager.Tests.Configurations.Docker;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for DockerServiceConfiguration
|
||||
/// </summary>
|
||||
public class DockerServiceConfigurationTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests that the DockerServiceConfiguration constructor initializes with the correct default values for Docker integration.
|
||||
/// Setup: Creates a new DockerServiceConfiguration instance using the default constructor.
|
||||
/// Expectation: CaddyContainerName should default to "caddy" and DockerHost should default to "unix:///var/run/docker.sock", ensuring proper Docker daemon communication and container identification for Caddy management.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Constructor_InitializesWithDefaultValues()
|
||||
{
|
||||
// Act
|
||||
var config = new DockerServiceConfiguration();
|
||||
|
||||
// Assert
|
||||
config.CaddyContainerName.Should().Be("caddy");
|
||||
config.DockerHost.Should().Be("unix:///var/run/docker.sock");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that both CaddyContainerName and DockerHost properties can be set and retrieved correctly with custom values.
|
||||
/// Setup: Creates a DockerServiceConfiguration instance and sets both properties to custom values for container name and Docker host connection.
|
||||
/// Expectation: Both properties should store and return the exact values provided, enabling flexible Docker configuration for different deployment environments and container naming schemes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Properties_CanBeSetAndRetrieved()
|
||||
{
|
||||
// Arrange
|
||||
var containerName = "my-caddy-container";
|
||||
var dockerHost = "tcp://localhost:2376";
|
||||
|
||||
// Act
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
CaddyContainerName = containerName,
|
||||
DockerHost = dockerHost
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.CaddyContainerName.Should().Be(containerName);
|
||||
config.DockerHost.Should().Be(dockerHost);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the CaddyContainerName property accepts various valid Docker container naming conventions.
|
||||
/// Setup: Uses parameterized test data with different container name formats including hyphens, underscores, and version suffixes.
|
||||
/// Expectation: The property should accept all valid Docker container names, supporting diverse naming conventions used in different deployment scenarios and environments.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("caddy")]
|
||||
[InlineData("my-caddy")]
|
||||
[InlineData("production-caddy")]
|
||||
[InlineData("caddy-server")]
|
||||
[InlineData("caddy_container")]
|
||||
[InlineData("caddy-v2")]
|
||||
public void CaddyContainerName_WithVariousNames_SetsCorrectly(string containerName)
|
||||
{
|
||||
// Act
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
CaddyContainerName = containerName
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.CaddyContainerName.Should().Be(containerName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the DockerHost property accepts various Docker daemon connection formats across different platforms.
|
||||
/// Setup: Uses parameterized test data with Unix socket, TCP, IP address, and Windows named pipe connection strings.
|
||||
/// Expectation: The property should accept all valid Docker host connection formats, supporting local and remote Docker daemon connections across Linux, Windows, and network-based Docker environments.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("unix:///var/run/docker.sock")]
|
||||
[InlineData("tcp://localhost:2376")]
|
||||
[InlineData("tcp://docker-host:2376")]
|
||||
[InlineData("tcp://192.168.1.100:2376")]
|
||||
[InlineData("npipe:////./pipe/docker_engine")]
|
||||
public void DockerHost_WithVariousHosts_SetsCorrectly(string dockerHost)
|
||||
{
|
||||
// Act
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
DockerHost = dockerHost
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.DockerHost.Should().Be(dockerHost);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that DockerHostWithEnvCheck prioritizes the DOCKER_HOST environment variable over the configured value when set.
|
||||
/// Setup: Sets DOCKER_HOST environment variable to a specific value and creates a configuration with a different DockerHost value.
|
||||
/// Expectation: The method should return the environment variable value, ensuring Docker client behavior consistency by respecting the standard DOCKER_HOST environment variable for Docker daemon connection.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DockerHostWithEnvCheck_WithEnvironmentVariableSet_ReturnsEnvironmentValue()
|
||||
{
|
||||
// Arrange
|
||||
var originalValue = Environment.GetEnvironmentVariable("DOCKER_HOST");
|
||||
var envValue = "tcp://env-host:2376";
|
||||
var configValue = "tcp://config-host:2376";
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", envValue);
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
DockerHost = configValue
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = config.DockerHostWithEnvCheck;
|
||||
|
||||
// Assert
|
||||
result.Should().Be(envValue);
|
||||
result.Should().NotBe(configValue);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", originalValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that DockerHostWithEnvCheck returns the configured DockerHost value when DOCKER_HOST environment variable is not set.
|
||||
/// Setup: Ensures DOCKER_HOST environment variable is null and creates a configuration with a specific DockerHost value.
|
||||
/// Expectation: The method should return the configured value, providing fallback behavior when environment variables are not available for Docker daemon connection configuration.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DockerHostWithEnvCheck_WithoutEnvironmentVariable_ReturnsConfigValue()
|
||||
{
|
||||
// Arrange
|
||||
var originalValue = Environment.GetEnvironmentVariable("DOCKER_HOST");
|
||||
var configValue = "tcp://config-host:2376";
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", null);
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
DockerHost = configValue
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = config.DockerHostWithEnvCheck;
|
||||
|
||||
// Assert
|
||||
result.Should().Be(configValue);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", originalValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that DockerHostWithEnvCheck returns the configured DockerHost value when DOCKER_HOST environment variable is empty.
|
||||
/// Setup: Sets DOCKER_HOST environment variable to an empty string and creates a configuration with a specific DockerHost value.
|
||||
/// Expectation: The method should return the configured value, treating empty environment variables as invalid and falling back to configuration for reliable Docker daemon connection.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DockerHostWithEnvCheck_WithEmptyEnvironmentVariable_ReturnsConfigValue()
|
||||
{
|
||||
// Arrange
|
||||
var originalValue = Environment.GetEnvironmentVariable("DOCKER_HOST");
|
||||
var configValue = "tcp://config-host:2376";
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", "");
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
DockerHost = configValue
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = config.DockerHostWithEnvCheck;
|
||||
|
||||
// Assert
|
||||
result.Should().Be(configValue);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", originalValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that DockerHostWithEnvCheck returns the configured DockerHost value when DOCKER_HOST environment variable contains only whitespace.
|
||||
/// Setup: Sets DOCKER_HOST environment variable to whitespace characters and creates a configuration with a specific DockerHost value.
|
||||
/// Expectation: The method should return the configured value, treating whitespace-only environment variables as invalid and ensuring robust Docker daemon connection configuration.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DockerHostWithEnvCheck_WithWhitespaceEnvironmentVariable_ReturnsConfigValue()
|
||||
{
|
||||
// Arrange
|
||||
var originalValue = Environment.GetEnvironmentVariable("DOCKER_HOST");
|
||||
var configValue = "tcp://config-host:2376";
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", " ");
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
DockerHost = configValue
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = config.DockerHostWithEnvCheck;
|
||||
|
||||
// Assert
|
||||
result.Should().Be(configValue);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", originalValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that DockerHostWithEnvCheck returns the default Docker host value when both environment variable and configuration are not set.
|
||||
/// Setup: Ensures DOCKER_HOST environment variable is null and creates a default DockerServiceConfiguration instance.
|
||||
/// Expectation: The method should return the default "unix:///var/run/docker.sock" value, providing a reliable fallback for standard Docker daemon connection on Unix systems.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DockerHostWithEnvCheck_WithBothNotSet_ReturnsDefaultValue()
|
||||
{
|
||||
// Arrange
|
||||
var originalValue = Environment.GetEnvironmentVariable("DOCKER_HOST");
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", null);
|
||||
var config = new DockerServiceConfiguration();
|
||||
|
||||
// Act
|
||||
var result = config.DockerHostWithEnvCheck;
|
||||
|
||||
// Assert
|
||||
result.Should().Be("unix:///var/run/docker.sock");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", originalValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the static Docker constant has the correct string value.
|
||||
/// Setup: Accesses the static DockerServiceConfiguration.Docker constant.
|
||||
/// Expectation: The constant should return "Docker", providing a consistent identifier for the Docker service throughout the application for configuration and service management purposes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Constant_Docker_HasCorrectValue()
|
||||
{
|
||||
// Assert
|
||||
DockerServiceConfiguration.Docker.Should().Be("Docker");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that both CaddyContainerName and DockerHost properties can be modified after the object has been created and initialized.
|
||||
/// Setup: Creates a DockerServiceConfiguration instance with default values, then changes both properties to new values.
|
||||
/// Expectation: Both properties should be mutable and accept new values, enabling runtime reconfiguration of Docker service settings for dynamic deployment scenarios.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Properties_CanBeModifiedAfterCreation()
|
||||
{
|
||||
// Arrange
|
||||
var config = new DockerServiceConfiguration();
|
||||
var newContainerName = "updated-caddy";
|
||||
var newDockerHost = "tcp://updated-host:2376";
|
||||
|
||||
// Act
|
||||
config.CaddyContainerName = newContainerName;
|
||||
config.DockerHost = newDockerHost;
|
||||
|
||||
// Assert
|
||||
config.CaddyContainerName.Should().Be(newContainerName);
|
||||
config.DockerHost.Should().Be(newDockerHost);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the CaddyContainerName property accepts empty, whitespace, and null values.
|
||||
/// Setup: Uses parameterized test data with empty string, whitespace, and null values for container name.
|
||||
/// Expectation: The property should accept all these values without validation restrictions, supporting edge cases where container name might be cleared or undefined in certain deployment scenarios.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void CaddyContainerName_WithEmptyOrNullValues_SetsCorrectly(string? containerName)
|
||||
{
|
||||
// Act
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
CaddyContainerName = containerName!
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.CaddyContainerName.Should().Be(containerName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that the DockerHost property accepts empty, whitespace, and null values.
|
||||
/// Setup: Uses parameterized test data with empty string, whitespace, and null values for Docker host connection.
|
||||
/// Expectation: The property should accept all these values without validation restrictions, supporting scenarios where Docker host configuration might be cleared or undefined.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void DockerHost_WithEmptyOrNullValues_SetsCorrectly(string? dockerHost)
|
||||
{
|
||||
// Act
|
||||
var config = new DockerServiceConfiguration
|
||||
{
|
||||
DockerHost = dockerHost!
|
||||
};
|
||||
|
||||
// Assert
|
||||
config.DockerHost.Should().Be(dockerHost);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that DockerHostWithEnvCheck returns consistent results when called multiple times with the same environment variable value.
|
||||
/// Setup: Sets DOCKER_HOST environment variable to a specific value and calls DockerHostWithEnvCheck multiple times on the same configuration instance.
|
||||
/// Expectation: All calls should return the same environment variable value, ensuring consistent behavior and reliable Docker daemon connection configuration across multiple property accesses.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DockerHostWithEnvCheck_MultipleCallsWithSameEnvironment_ReturnsConsistentResults()
|
||||
{
|
||||
// Arrange
|
||||
var originalValue = Environment.GetEnvironmentVariable("DOCKER_HOST");
|
||||
var envValue = "tcp://consistent-host:2376";
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", envValue);
|
||||
var config = new DockerServiceConfiguration();
|
||||
|
||||
// Act
|
||||
var result1 = config.DockerHostWithEnvCheck;
|
||||
var result2 = config.DockerHostWithEnvCheck;
|
||||
|
||||
// Assert
|
||||
result1.Should().Be(envValue);
|
||||
result2.Should().Be(envValue);
|
||||
result1.Should().Be(result2);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", originalValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that DockerHostWithEnvCheck dynamically reflects changes to the DOCKER_HOST environment variable during execution.
|
||||
/// Setup: Creates a configuration instance and changes the DOCKER_HOST environment variable between calls to DockerHostWithEnvCheck.
|
||||
/// Expectation: The method should return the current environment variable value for each call, ensuring real-time responsiveness to environment changes for dynamic Docker daemon connection management.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DockerHostWithEnvCheck_EnvironmentChangeDuringExecution_ReflectsChange()
|
||||
{
|
||||
// Arrange
|
||||
var originalValue = Environment.GetEnvironmentVariable("DOCKER_HOST");
|
||||
var firstEnvValue = "tcp://first-host:2376";
|
||||
var secondEnvValue = "tcp://second-host:2376";
|
||||
|
||||
try
|
||||
{
|
||||
var config = new DockerServiceConfiguration();
|
||||
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", firstEnvValue);
|
||||
var firstResult = config.DockerHostWithEnvCheck;
|
||||
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", secondEnvValue);
|
||||
var secondResult = config.DockerHostWithEnvCheck;
|
||||
|
||||
// Assert
|
||||
firstResult.Should().Be(firstEnvValue);
|
||||
secondResult.Should().Be(secondEnvValue);
|
||||
firstResult.Should().NotBe(secondResult);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup
|
||||
Environment.SetEnvironmentVariable("DOCKER_HOST", originalValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that multiple DockerServiceConfiguration instances maintain independent property values for both CaddyContainerName and DockerHost.
|
||||
/// Setup: Creates two separate DockerServiceConfiguration instances with different values for both CaddyContainerName and DockerHost properties.
|
||||
/// Expectation: Each instance should maintain its own property values independently, ensuring proper isolation when managing multiple Docker service configurations simultaneously in complex deployment scenarios.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void MultipleInstances_HaveIndependentValues()
|
||||
{
|
||||
// Arrange
|
||||
var config1 = new DockerServiceConfiguration
|
||||
{
|
||||
CaddyContainerName = "caddy1",
|
||||
DockerHost = "tcp://host1:2376"
|
||||
};
|
||||
var config2 = new DockerServiceConfiguration
|
||||
{
|
||||
CaddyContainerName = "caddy2",
|
||||
DockerHost = "tcp://host2:2376"
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
config1.CaddyContainerName.Should().Be("caddy1");
|
||||
config2.CaddyContainerName.Should().Be("caddy2");
|
||||
config1.DockerHost.Should().Be("tcp://host1:2376");
|
||||
config2.DockerHost.Should().Be("tcp://host2:2376");
|
||||
|
||||
config1.CaddyContainerName.Should().NotBe(config2.CaddyContainerName);
|
||||
config1.DockerHost.Should().NotBe(config2.DockerHost);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user