-
Notifications
You must be signed in to change notification settings - Fork 171
Fix DbGate integration to handle resource names with hyphens #1107
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
Changes from all commits
3be7c4b
16b5474
6ff08fa
46c1820
bb26e40
ce14ba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,4 +87,26 @@ public static IResourceBuilder<DbGateContainerResource> AddDbGate(this IDistribu | |
| return dbGateContainerBuilder; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sanitizes a resource name to be used as a connection ID in DbGate environment variables. | ||
| /// </summary> | ||
| /// <param name="resourceName">The resource name to sanitize.</param> | ||
| /// <returns>A sanitized connection ID safe for use in environment variable names.</returns> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// This method performs basic sanitization by replacing hyphens with underscores, as hyphens are not valid | ||
| /// in Linux environment variable names. | ||
| /// </para> | ||
| /// <para> | ||
| /// Note: Linux environment variable names have additional constraints (must contain only letters, numbers, and underscores, | ||
| /// and cannot start with a number). This method does not validate or enforce these additional constraints. | ||
| /// Resource names should follow standard naming conventions to ensure compatibility. | ||
| /// </para> | ||
| /// </remarks> | ||
| public static string SanitizeConnectionId(string resourceName) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(resourceName); | ||
| return resourceName.Replace('-', '_'); | ||
| } | ||
|
Comment on lines
+107
to
+111
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
SanitizeConnectionIdmethod lacks direct unit tests. While integration tests verify the sanitization works end-to-end in MySQL, there should be unit tests specifically for this method to cover edge cases like multiple hyphens, leading/trailing hyphens, empty strings (if allowed), and strings without hyphens. Consider adding tests totests/CommunityToolkit.Aspire.Hosting.DbGate.Tests/DbGatePublicApiTests.cs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comprehensive unit tests for
SanitizeConnectionIdtoDbGatePublicApiTests.cs, covering edge cases including multiple hyphens, leading/trailing hyphens, empty strings, and strings without hyphens. All tests pass. (commit 46c1820)