-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
1 parent
2e5a33a
commit c44f6d4
Showing
12 changed files
with
159 additions
and
23 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,3 @@ | ||
FROM alpine:latest | ||
|
||
LABEL maintainer="IAm@AndreHofmeister.com" |
Binary file not shown.
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
40 changes: 40 additions & 0 deletions
40
src/DotNet.Testcontainers.Tests/Unit/ImageFromDockerfileTest.cs
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,40 @@ | ||
namespace DotNet.Testcontainers.Tests.Unit | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using DotNet.Testcontainers.Core.Builder; | ||
using Xunit; | ||
|
||
public class ImageFromDockerfileTest | ||
{ | ||
[Fact] | ||
public async Task DockerfileDoesNotExist() | ||
{ | ||
await Assert.ThrowsAsync<ArgumentException>(() => | ||
new ImageFromDockerfileBuilder() | ||
.WithDockerfileDirectory(string.Empty) | ||
.Build()); | ||
} | ||
|
||
[Fact] | ||
public async Task DockerfileDirectoryDoesNotExist() | ||
{ | ||
await Assert.ThrowsAsync<ArgumentException>(() => | ||
new ImageFromDockerfileBuilder() | ||
.WithDockerfileDirectory("DoesNotExist") | ||
.Build()); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleDockerfile() | ||
{ | ||
var imageFromDockerfile = await new ImageFromDockerfileBuilder() | ||
.WithName("alpine:custom") | ||
.WithDockerfileDirectory("Assets") | ||
.WithDeleteIfExits(false) | ||
.Build(); | ||
|
||
Assert.NotEmpty(imageFromDockerfile); | ||
} | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/DotNet.Testcontainers/Core/Builder/IImageFromDockerfileBuilder.cs
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,18 @@ | ||
namespace DotNet.Testcontainers.Core.Builder | ||
{ | ||
using System.Threading.Tasks; | ||
using DotNet.Testcontainers.Core.Images; | ||
|
||
public interface IImageFromDockerfileBuilder | ||
{ | ||
IImageFromDockerfileBuilder WithName(string name); | ||
|
||
IImageFromDockerfileBuilder WithName(IDockerImage image); | ||
|
||
IImageFromDockerfileBuilder WithDockerfileDirectory(string dockerfileDirectory); | ||
|
||
IImageFromDockerfileBuilder WithDeleteIfExits(bool deleteIfExits); | ||
|
||
Task<string> Build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/DotNet.Testcontainers/Core/Builder/ImageFromDockerfileBuilder.cs
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,40 @@ | ||
namespace DotNet.Testcontainers.Core.Builder | ||
{ | ||
using System.Threading.Tasks; | ||
using DotNet.Testcontainers.Clients; | ||
using DotNet.Testcontainers.Core.Images; | ||
using DotNet.Testcontainers.Core.Models; | ||
|
||
public class ImageFromDockerfileBuilder : IImageFromDockerfileBuilder | ||
{ | ||
private readonly ImageFromDockerfileConfiguration configuration = new ImageFromDockerfileConfiguration(); | ||
|
||
public IImageFromDockerfileBuilder WithName(string image) | ||
{ | ||
return this.WithName(new TestcontainersImage(image)); | ||
} | ||
|
||
public IImageFromDockerfileBuilder WithName(IDockerImage image) | ||
{ | ||
this.configuration.Image = image.Image; | ||
return this; | ||
} | ||
|
||
public IImageFromDockerfileBuilder WithDockerfileDirectory(string dockerfileDirectory) | ||
{ | ||
this.configuration.DockerfileDirectory = dockerfileDirectory; | ||
return this; | ||
} | ||
|
||
public IImageFromDockerfileBuilder WithDeleteIfExits(bool deleteIfExits) | ||
{ | ||
this.configuration.DeleteIfExits = deleteIfExits; | ||
return this; | ||
} | ||
|
||
public Task<string> Build() | ||
{ | ||
return TestcontainersClient.Instance.BuildAsync(this.configuration); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/DotNet.Testcontainers/Core/Models/ImageFromDockerfileConfiguration.cs
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,13 @@ | ||
namespace DotNet.Testcontainers.Core.Models | ||
{ | ||
using System; | ||
|
||
internal class ImageFromDockerfileConfiguration | ||
{ | ||
public string Image { get; set; } = Guid.NewGuid().ToString("n"); | ||
|
||
public string DockerfileDirectory { get; set; } = "."; | ||
|
||
public bool DeleteIfExits { get; set; } = true; | ||
} | ||
} |
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
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