<commit_before>﻿using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Ductus.FluentDocker.Commands;
using Ductus.FluentDocker.Extensions;
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker.Services;
using Ductus.FluentDocker.Services.Extensions;
using Ductus.FluentDocker.Services.Impl;
using Ductus.FluentDocker.Tests.Compose;
using Ductus.FluentDocker.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ductus.FluentDocker.Tests.CommandTests
{
  [TestClass]
  public class ComposeCommandTests : FluentDockerTestBase
  {
    [ClassInitialize]
    public static void Initialize(TestContext ctx)
    {
      Utilities.LinuxMode();
    }

    [TestMethod]
    public async Task
      ComposeByBuildImageAddNgixAsLoadBalancerTwoNodesAsHtmlServeAndRedisAsDbBackendShouldWorkAsCluster()
    {
      // Extract compose file and it's dependencies to a temp folder
      var fullPath = (TemplateString) @"${TEMP}\fluentdockertest\${RND}";
      var file = Path.Combine(fullPath, "docker-compose.yml");
      typeof(NsResolver).ResourceExtract(fullPath);

      try
      {
        var result = DockerHost.Host.ComposeUp(composeFile: file, certificates: DockerHost.Certificates);
        Assert.IsTrue(result.Success);

        var ids = DockerHost.Host.ComposePs(composeFile: file, certificates: DockerHost.Certificates);
        Assert.IsTrue(ids.Success);
        Assert.AreEqual(5, ids.Data.Count);

        // Find the nginx docker container
        DockerContainerService svc = null;
        foreach (var id in ids.Data)
        {
          var inspect = DockerHost.Host.InspectContainer(id, DockerHost.Certificates);
          Assert.IsTrue(inspect.Success);

          if (inspect.Data.Name.Contains("_nginx_"))
          {
            svc = new DockerContainerService(inspect.Data.Name.Substring(1), id, DockerHost.Host,
              inspect.Data.State.ToServiceState(),
              DockerHost.Certificates, false, false);
            break;
          }
        }

        Assert.IsNotNull(svc);

        var ep = svc.ToHostExposedEndpoint("80/tcp");
        Assert.IsNotNull(ep);

        var round1 = await $"http://{ep.Address}:{ep.Port}".Wget();
        Assert.AreEqual("This page has been viewed 1 times!", round1);

        var round2 = await $"http://{ep.Address}:{ep.Port}".Wget();
        Assert.AreEqual("This page has been viewed 2 times!", round2);
      }
      finally
      {
        DockerHost.Host.ComposeDown(composeFile: file, certificates: DockerHost.Certificates, removeVolumes: true,
          removeOrphanContainers: true);
      }
    }

    [TestMethod]
//    [Ignore]
    public void Issue79_DockerComposeOnDockerMachineShallWork()
    {
      var fullPath = (TemplateString) @"${TEMP}\fluentdockertest\${RND}";
      var file = Path.Combine(fullPath, "docker-compose.yml");
      typeof(NsResolver).ResourceExtract(fullPath);

      var hostService = new DockerHostService("test-machine");<commit_msg>Add ingore to a machine test.<commit_after>﻿using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Ductus.FluentDocker.Commands;
using Ductus.FluentDocker.Extensions;
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker.Services;
using Ductus.FluentDocker.Services.Extensions;
using Ductus.FluentDocker.Services.Impl;
using Ductus.FluentDocker.Tests.Compose;
using Ductus.FluentDocker.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ductus.FluentDocker.Tests.CommandTests
{
  [TestClass]
  public class ComposeCommandTests : FluentDockerTestBase
  {
    [ClassInitialize]
    public static void Initialize(TestContext ctx)
    {
      Utilities.LinuxMode();
    }

    [TestMethod]
    public async Task
      ComposeByBuildImageAddNgixAsLoadBalancerTwoNodesAsHtmlServeAndRedisAsDbBackendShouldWorkAsCluster()
    {
      // Extract compose file and it's dependencies to a temp folder
      var fullPath = (TemplateString) @"${TEMP}\fluentdockertest\${RND}";
      var file = Path.Combine(fullPath, "docker-compose.yml");
      typeof(NsResolver).ResourceExtract(fullPath);

      try
      {
        var result = DockerHost.Host.ComposeUp(composeFile: file, certificates: DockerHost.Certificates);
        Assert.IsTrue(result.Success);

        var ids = DockerHost.Host.ComposePs(composeFile: file, certificates: DockerHost.Certificates);
        Assert.IsTrue(ids.Success);
        Assert.AreEqual(5, ids.Data.Count);

        // Find the nginx docker container
        DockerContainerService svc = null;
        foreach (var id in ids.Data)
        {
          var inspect = DockerHost.Host.InspectContainer(id, DockerHost.Certificates);
          Assert.IsTrue(inspect.Success);

          if (inspect.Data.Name.Contains("_nginx_"))
          {
            svc = new DockerContainerService(inspect.Data.Name.Substring(1), id, DockerHost.Host,
              inspect.Data.State.ToServiceState(),
              DockerHost.Certificates, false, false);
            break;
          }
        }

        Assert.IsNotNull(svc);

        var ep = svc.ToHostExposedEndpoint("80/tcp");
        Assert.IsNotNull(ep);

        var round1 = await $"http://{ep.Address}:{ep.Port}".Wget();
        Assert.AreEqual("This page has been viewed 1 times!", round1);

        var round2 = await $"http://{ep.Address}:{ep.Port}".Wget();
        Assert.AreEqual("This page has been viewed 2 times!", round2);
      }
      finally
      {
        DockerHost.Host.ComposeDown(composeFile: file, certificates: DockerHost.Certificates, removeVolumes: true,
          removeOrphanContainers: true);
      }
    }

    [TestMethod]
    [Ignore]
    public void Issue79_DockerComposeOnDockerMachineShallWork()
    {
      var fullPath = (TemplateString) @"${TEMP}\fluentdockertest\${RND}";
      var file = Path.Combine(fullPath, "docker-compose.yml");
      typeof(NsResolver).ResourceExtract(fullPath);

      var hostService = new DockerHostService("test-machine");
{'fraction_non_alphanumeric': 0.10879706764411863, 'fraction_numerical': 0.003998667110963012, 'mean_word_length': 3.1949685534591197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7248133', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1805, 'n_words': 334}