Skip to content

Commit

Permalink
Add tests for the Service.WithBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Feb 12, 2022
1 parent 48e94d6 commit b2edbdd
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Aviationexam.DockerComposeBuilder.Builders;
using Aviationexam.DockerComposeBuilder.Enums;
using Aviationexam.DockerComposeBuilder.Extensions;
using Aviationexam.DockerComposeBuilder.Model;
using Aviationexam.DockerComposeBuilder.Model.Services;
using System;

var dbUser = "root";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Aviationexam.DockerComposeBuilder.Builders;
using Aviationexam.DockerComposeBuilder.Extensions;
using Aviationexam.DockerComposeBuilder.Model.Services.BuildArguments;
using System.Collections.Generic;
using Xunit;

namespace Aviationexam.DockerComposeBuilder.Tests;
Expand All @@ -14,6 +16,90 @@ public void EmptyComposeBuilderTest()

var result = compose.Serialize();

Assert.Equal("version: \"3.7\"\n", result);
Assert.Equal(
@"version: ""3.7""
", result
);
}

[Fact]
public void ServiceWithImageTest()
{
var compose = Builder.MakeCompose()
.WithServices(Builder.MakeService("a-service")
.WithImage("aviationexam/a-service")
.Build()
)
.Build();

var result = compose.Serialize();

Assert.Equal(
@"version: ""3.7""
services:
a-service:
image: ""aviationexam/a-service""
", result);
}

[Fact]
public void ServiceWithBuildTest()
{
var compose = Builder.MakeCompose()
.WithServices(Builder.MakeService("a-service")
.WithImage("aviationexam/a-service")
.WithBuild(x => x
.WithDockerfile("a.dockerfile")
)
.Build()
)
.Build();

var result = compose.Serialize();

Assert.Equal(
@"version: ""3.7""
services:
a-service:
image: ""aviationexam/a-service""
build:
dockerfile: ""a.dockerfile""
", result);
}

[Fact]
public void ServiceWithBuildArgumentsTest()
{
var compose = Builder.MakeCompose()
.WithServices(Builder.MakeService("a-service")
.WithImage("aviationexam/a-service")
.WithBuild(x => x
.WithContext(".")
.WithDockerfile("a.dockerfile")
.WithArguments(a => a
.AddWithoutValue("ENV_1")
.Add(new KeyValuePair<string, string>("ENV_2", "value"))
.Add(new BuildArgument("ENV_3", "value"))
)
)
.Build()
)
.Build();

var result = compose.Serialize();

Assert.Equal(
@"version: ""3.7""
services:
a-service:
image: ""aviationexam/a-service""
build:
context: "".""
dockerfile: ""a.dockerfile""
args:
- ""ENV_1""
- ""ENV_2=value""
- ""ENV_3=value""
", result);
}
}

0 comments on commit b2edbdd

Please sign in to comment.