public async Task ShouldReturnConfigurationThatIsApplicableAndHighestPriority()
        {
            // arrange
            var mockConfig = new DockerClientConfiguration(new Uri("tcp://abcd"));

            // only 1 provider should return the mock config
            var provider1 = new MockDockerClientProvider(false, 1000, () => null, ct => Task.FromResult(true));
            var provider2 = new MockDockerClientProvider(true, 1000, () => mockConfig, ct => Task.FromResult(true));
            var provider3 = new MockDockerClientProvider(true, 100, () => null, ct => Task.FromResult(true));
            var provider4 = new MockDockerClientProvider(true, 20000, () => null, ct => Task.FromResult(false));

            var factory = new DockerClientFactory(new NullLogger <DockerClientFactory>(),
                                                  new List <IDockerClientProvider>
            {
                provider1,
                provider2,
                provider3,
                provider4
            });

            // act
            var result = await factory.Create();

            // assert
            Assert.Equal(mockConfig, result.Configuration);
        }
Example #2
0
 public TestContainersEnvironmentService(IServiceProvider serviceProvider,
                                         ITestEnvironmentContextAccessor testEnvironmentContextAccessor,
                                         DockerClientFactory dockerClientFactory)
 {
     _serviceProvider = serviceProvider;
     _testEnvironmentContextAccessor = testEnvironmentContextAccessor;
     _dockerClientFactory            = dockerClientFactory;
 }
Example #3
0
 public ContainersMonitoringServiceFactory(ILogger <ContainersMonitoringServiceFactory> logger, ILoggerFactory loggerFactory, DockerClientFactory dockerClientFactory, GlobalCancellationToken globalCancellation, CommandsExecutorFactory commandsExecutorFactory, EventsBus eventsBus)
 {
     this.logger                  = logger;
     this.loggerFactory           = loggerFactory;
     this.dockerClientFactory     = dockerClientFactory;
     this.globalCancellation      = globalCancellation;
     this.commandsExecutorFactory = commandsExecutorFactory;
     this.eventsBus               = eventsBus;
 }
        public GenericContainerFixture()
        {
            HostPathBinding =
                new KeyValuePair <string, string>(Directory.GetCurrentDirectory(), PlatformSpecific.BindPath);
            FileTouchedByCommand = PlatformSpecific.TouchedFilePath;
            WorkingDirectory     = PlatformSpecific.WorkingDirectory;

            Container = new ContainerBuilder <GenericContainer>()
                        .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection())
                        .ConfigureAppConfiguration((context, builder) => builder.AddInMemoryCollection())
                        .ConfigureDockerImageName(PlatformSpecific.TinyDockerImage)
                        .ConfigureLogging(builder => builder.AddConsole())
                        .ConfigureContainer((context, container) =>
            {
                container.Labels.Add(CustomLabel.Key, CustomLabel.Value);
                container.Env[InjectedEnvVar.Key] = InjectedEnvVar.Value;
                container.ExposedPorts.Add(ExposedPort);

                /*
                 * to do something like `docker run -p 2345:34567 alpine:latest`,
                 * both expose port and port binding must be set
                 */
                container.ExposedPorts.Add(PortBinding.Key);
                container.PortBindings.Add(PortBinding.Key, PortBinding.Value);
                container.BindMounts.Add(new Bind
                {
                    HostPath      = HostPathBinding.Key,
                    ContainerPath = HostPathBinding.Value,
                    AccessMode    = AccessMode.ReadOnly
                });
                container.WorkingDirectory = WorkingDirectory;
                container.Command          = PlatformSpecific.ShellCommand(
                    $"{PlatformSpecific.Touch} {FileTouchedByCommand}; {PlatformSpecific.Shell}")
                                             .ToList();
            })
                        .Build();

            DockerClient = new DockerClientFactory().Create();
        }
Example #5
0
        public ContainersMonitoringService(ILogger logger,
                                           string groupName,
                                           ContainersGroupConfiguration configuration,
                                           DockerClientFactory dockerClientFactory,
                                           GlobalCancellationToken globalCancellation,
                                           CommandsExecutorFactory commandsExecutorFactory,
                                           EventsBus eventsBus)
        {
            this.logger                  = logger;
            this.groupName               = groupName;
            this.configuration           = configuration;
            this.dockerClientFactory     = dockerClientFactory;
            this.globalCancellation      = globalCancellation;
            this.commandsExecutorFactory = commandsExecutorFactory;
            this.eventsBus               = eventsBus;

            this.listParameters = new ContainersListParameters()
            {
                All     = true,
                Filters = ComposeFilter(configuration)
            };
        }
Example #6
0
 protected Container(ContainerConfiguration configuration)
 {
     Configuration = configuration;
     _dockerClient = DockerClientFactory.GetClient();
 }