-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Net; | ||
using DotNet.Testcontainers.Builders; | ||
using DotNet.Testcontainers.Containers; | ||
|
||
namespace Promote.NuGet.Feeds.Tests; | ||
|
||
public sealed class LocalNugetFeed : IAsyncDisposable | ||
{ | ||
private readonly IContainer _container; | ||
|
||
public string FeedUrl { get; } | ||
|
||
public string ApiKey { get; } | ||
|
||
private LocalNugetFeed(IContainer container, string feedUrl, string apiKey) | ||
{ | ||
_container = container; | ||
FeedUrl = feedUrl; | ||
ApiKey = apiKey; | ||
} | ||
|
||
public static async Task<LocalNugetFeed> Create() | ||
{ | ||
var buffer = new byte[64]; | ||
Random.Shared.NextBytes(buffer); | ||
var apiKey = Convert.ToBase64String(buffer); | ||
|
||
const ushort bagetterPort = 8080; | ||
|
||
var container = new ContainerBuilder() | ||
.WithImage("bagetter/bagetter:1.0.0") | ||
.WithEnvironment("ApiKey", apiKey) | ||
.WithPortBinding(bagetterPort, true) | ||
.WithWaitStrategy(Wait.ForUnixContainer() | ||
.UntilHttpRequestIsSucceeded( | ||
r => r.ForPort(bagetterPort).ForPath("/").ForStatusCode(HttpStatusCode.OK))) | ||
.Build(); | ||
|
||
await container.StartAsync(); | ||
|
||
var feedUrl = new UriBuilder("http", container.Hostname, container.GetMappedPublicPort(bagetterPort), "/v3/index.json").Uri.ToString(); | ||
|
||
return new LocalNugetFeed(container, feedUrl, apiKey); | ||
} | ||
|
||
public ValueTask DisposeAsync() | ||
{ | ||
return _container.DisposeAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters