示例#1
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Press any key to start LocalStack container");
            Console.ReadLine();

            ITestcontainersBuilder <TestcontainersContainer> localStackBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                                                                 .WithName("LocalStack-0.12.10")
                                                                                 .WithImage("localstack/localstack:0.12.10")
                                                                                 .WithCleanUp(true)
                                                                                 .WithEnvironment("DEFAULT_REGION", "eu-central-1")
                                                                                 .WithEnvironment("SERVICES", "iam,lambda,dynamodb,apigateway,s3,sns,cloudformation,cloudwatch,sts")
                                                                                 .WithEnvironment("DOCKER_HOST", "unix:///var/run/docker.sock")
                                                                                 .WithEnvironment("LS_LOG", "info")
                                                                                 .WithPortBinding(4566, 4566);

            TestcontainersContainer container = localStackBuilder.Build();

            Console.WriteLine("Starting LocalStack Container");
            await container.StartAsync();

            Console.WriteLine("LocalStack Container started");

            Console.WriteLine("Press any key to stop LocalStack container");
            Console.ReadLine();

            Console.WriteLine("Stopping LocalStack Container");
            await container.StopAsync();

            Console.WriteLine("LocalStack Container stopped");
        }
        public KafkaContainer(string zookeeperAddress)
        {
            var dockerHost = Environment.GetEnvironmentVariable("DOCKER_HOST");

            if (string.IsNullOrEmpty(dockerHost))
            {
                dockerHost = "unix:/var/run/docker.sock";
            }

            Console.WriteLine($"dockerHost: {dockerHost}");

            _container = new TestcontainersBuilder <TestcontainersContainer>()
                         .WithDockerEndpoint(dockerHost)
                         .WithImage(new DockerImage("confluentinc/cp-kafka:5.5.1"))
                         .WithExposedPort(Port)
                         .WithPortBinding(Port, Port)
                         .WithEnvironment("KAFKA_ADVERTISED_LISTENERS",
                                          "PLAINTEXT://localhost:29092,PLAINTEXT_HOST://localhost:9092")
                         .WithEnvironment("KAFKA_ZOOKEEPER_CONNECT", zookeeperAddress)
                         .WithEnvironment("KAFKA_BROKER_ID", "1")
                         .WithEnvironment("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT")
                         .WithEnvironment("KAFKA_INTER_BROKER_LISTENER_NAME", "PLAINTEXT")
                         .WithEnvironment("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "1")
                         .WithName("kafka-testcontainer")
                         .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(_outStream, _errorStream))
                         .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(Port))
                         .Build();
        }
    public LoadDriver(IDockerNetwork network, NamingConvention namingConvention, TestConfig testConfig)
    {
        _network = network ?? throw new ArgumentNullException(nameof(network));
        if (namingConvention == null)
        {
            throw new ArgumentNullException(nameof(namingConvention));
        }
        if (testConfig == null)
        {
            throw new ArgumentNullException(nameof(testConfig));
        }

        _logStream    = File.Create(Path.Combine(namingConvention.ContainerLogs, "k6.txt"));
        _resultStream = File.Create(Path.Combine(namingConvention.AgentResults, K6ResultsFile));

        _hostScriptPath = Path.Combine(Directory.GetCurrentDirectory(), "K6", "basic.js");
        _container      = new TestcontainersBuilder <TestcontainersContainer>()
                          .WithImage(LoadDriveImageName)
                          .WithName($"{OverheadTest.Prefix}-k6-load")
                          .WithNetwork(_network)
                          .WithCommand("run",
                                       "-u", testConfig.ConcurrentConnections.ToString(),
                                       "-e", $"ESHOP_HOSTNAME={EshopApp.ContainerName}",
                                       "-i", testConfig.Iterations.ToString(),
                                       "--rps", testConfig.MaxRequestRate.ToString(),
                                       ContainerScriptPath,
                                       "--summary-export", ContainerResultsPath)
                          .WithBindMount(_hostScriptPath, ContainerScriptPath)
                          .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(_logStream, _logStream))
                          .Build();
    }
        public LocalStackFixture(IOptions <LocalStackOptions> options, Amazon.Extensions.NETCore.Setup.AWSOptions awsOptions)
        {
            var localStackBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                    .WithImage("localstack/localstack")
                                    .WithCleanUp(true)
                                    .WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole())
                                    .WithEnvironment("DEFAULT_REGION", "eu-central-1")
                                    .WithEnvironment("SERVICES", "s3")
                                    .WithEnvironment("DOCKER_HOST", "unix:///var/run/docker.sock")
                                    .WithEnvironment("DEBUG", "1")
                                    .WithPortBinding(4566, 4566);

            if (awsOptions != null)
            {
                if (awsOptions.Credentials != null)
                {
                    var awsCreds = awsOptions.Credentials.GetCredentials();
                    localStackBuilder.WithEnvironment("AWS_ACCESS_KEY_ID", awsCreds.AccessKey)
                    .WithEnvironment("AWS_SECRET_ACCESS_KEY", awsCreds.SecretKey);
                }
            }

            _localStackContainer = localStackBuilder.Build();
            this.options         = options;
        }
示例#5
0
        public async Task TearDownIntegrationTest()
        {
            client.Dispose();
            client = null;
            await container.StopAsync();

            container = null;
        }
示例#6
0
        public async Task <IZeebeClient> SetupIntegrationTest()
        {
            container = CreateZeebeContainer();
            await container.StartAsync();

            client = CreateZeebeClient();
            await AwaitBrokerReadiness();

            return(client);
        }
示例#7
0
        public MockServerFixture()
        {
            _container = CreateMySqlContainer();

            Hostname = _container.Hostname;
            Port     = _container.GetMappedPublicPort("8882");
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new OrderProfile());
            });

            Mapper = mockMapper.CreateMapper();
        }
        public LocalStackFixture()
        {
            var localStackBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                    .WithImage("localstack/localstack")
                                    .WithCleanUp(true)
                                    .WithEnvironment("DEFAULT_REGION", "eu-central-1")
                                    .WithEnvironment("SERVICES", "dynamodb,sqs")
                                    .WithEnvironment("DOCKER_HOST", "unix:///var/run/docker.sock")
                                    .WithEnvironment("DEBUG", "1")
                                    .WithPortBinding(4566, 4566);

            _localStackContainer = localStackBuilder.Build();
        }
示例#9
0
    public void StartLocalStackContainer()
    {
        var localStackBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                .WithImage("localstack/localstack")
                                .WithCleanUp(true)
                                .WithEnvironment("DEFAULT_REGION", "ap-southeast-2")
                                .WithEnvironment("SERVICES", "sqs")
                                .WithEnvironment("DOCKER_HOST", "unix:///var/run/docker.sock")
                                .WithEnvironment("DEBUG", "1")
                                .WithPortBinding(4566, 4566);

        _localStackContainer = localStackBuilder.Build();
        _localStackContainer.StartAsync();
    }
示例#10
0
 public async Task OneTimeSetup()
 {
     _testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                              .WithImage("postgres:12.2")
                              .WithName("gto-infra-test")
                              .WithPortBinding(5432)
                              .WithEnvironment("POSTGRES_USER", PostgresUser)
                              .WithEnvironment("POSTGRES_PASSWORD", PostgresPassword)
                              .WithEnvironment("POSTGRES_DB", PostgresDb)
                              .WithCleanUp(true)
                              .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(5432));
     _postgres = _testcontainersBuilder.Build();
     await _postgres.StartAsync();
 }
示例#11
0
    public EshopApp(IDockerNetwork network, CollectorBase collector, SqlServerBase sqlServer,
                    NamingConvention namingConvention, AgentConfig config)
    {
        if (network == null)
        {
            throw new ArgumentNullException(nameof(network));
        }
        if (collector == null)
        {
            throw new ArgumentNullException(nameof(collector));
        }
        if (sqlServer == null)
        {
            throw new ArgumentNullException(nameof(sqlServer));
        }
        if (namingConvention == null)
        {
            throw new ArgumentNullException(nameof(namingConvention));
        }
        if (config == null)
        {
            throw new ArgumentNullException(nameof(config));
        }

        _logStream    = File.Create(Path.Combine(namingConvention.ContainerLogs, "eshop-app.txt"));
        _resultStream = File.Create(Path.Combine(namingConvention.AgentResults, CounterResultsFile));

        var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                    .WithImage(config.DockerImageName)
                                    .WithName(ContainerName)
                                    .WithNetwork(network)
                                    .WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
                                    .WithEnvironment("SIGNALFX_ENDPOINT_URL", collector.TraceReceiverUrl)
                                    .WithEnvironment("SIGNALFX_PROFILER_LOGS_ENDPOINT", collector.LogsReceiverUrl)
                                    .WithEnvironment("ConnectionStrings__CatalogConnection", sqlServer.CatalogConnection)
                                    .WithEnvironment("ConnectionStrings__IdentityConnection", sqlServer.IdentityConnection)
                                    .WithEnvironment("Logging__LogLevel__Microsoft", "Warning")
                                    .WithEnvironment("Logging__LogLevel__Default", "Warning")
                                    .WithEnvironment("Logging__LogLevel__System", "Warning")
                                    .WithEnvironment("Logging__LogLevel__Microsoft.Hosting.Lifetime", "Information")
                                    .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(AppPort))
                                    .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(_logStream, _logStream));

        foreach (var envVar in config.AdditionalEnvVars)
        {
            testcontainersBuilder = testcontainersBuilder.WithEnvironment(envVar.Name, envVar.Value);
        }
        _container = testcontainersBuilder.Build();
    }
示例#12
0
        public PostgreSQLFixture()
        {
            if (_container == null)
            {
                _container = BuildConsulContainer();
                _container.StartAsync();

                // Let's wait for the container startup.
                Task.Delay(20 * 1000).Wait();
            }

            var dbContext = new DevicesContext(new DbContextOptionsBuilder().UseNpgsql(CONNECTION_STRING).Options);

            _dataProvider = new DataProvider(dbContext);
        }
示例#13
0
        public ElasticSearchInContainerFixture()
        {
            var testContainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                        .WithImage("elasticsearch:6.4.0")
                                        .WithName("elasticsearch-33333")
                                        .WithEnvironment("discovery.type", "single-node")
                                        .WithPortBinding(9200, 9200)
                                        .WithPortBinding(9300, 9300)
                                        .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(9200));

            testContainer = testContainersBuilder.Build();
            testContainer.StartAsync().Wait();

            InsertData();
        }
        public LocalStackLegacyFixture()
        {
            ITestcontainersBuilder <TestcontainersContainer> localStackBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                                                                 .WithName("LocalStackLegacy-0.11.4")
                                                                                 .WithImage("localstack/localstack:0.11.4")
                                                                                 .WithCleanUp(true)
                                                                                 .WithEnvironment("DEFAULT_REGION", "eu-central-1")
                                                                                 .WithEnvironment("SERVICES", "s3,dynamodb,sqs")
                                                                                 .WithEnvironment("DOCKER_HOST", "unix:///var/run/docker.sock")
                                                                                 .WithEnvironment("DEBUG", "1")
                                                                                 .WithPortBinding(4569, 4569)  // dynamo
                                                                                 .WithPortBinding(4576, 4576)  // sqs
                                                                                 .WithPortBinding(4572, 4572); // s3

            _localStackContainer = localStackBuilder.Build();
        }
        public ZookeeperContainer()
        {
            var dockerHost = Environment.GetEnvironmentVariable("DOCKER_HOST");

            if (string.IsNullOrEmpty(dockerHost))
            {
                dockerHost = "unix:/var/run/docker.sock";
            }

            _container = new TestcontainersBuilder <TestcontainersContainer>()
                         .WithDockerEndpoint(dockerHost)
                         .WithImage(new DockerImage("zookeeper:3.4.9"))
                         .WithExposedPort(Port)
                         .WithPortBinding(Port, Port)
                         .WithPortBinding(2888, 2888)
                         .WithPortBinding(3888, 3888)
                         .WithName("zookeeper-testcontainer")
                         .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(Port))
                         .Build();
        }
示例#16
0
        public async Task GlobalSetupAsync()
        {
            var instanceBaseUrl = Environment.GetEnvironmentVariable(BaseHassWSApiTest.TestsInstanceBaseUrlVar);

            if (instanceBaseUrl == null)
            {
                // Create temporary directory
                var tmpDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                Directory.CreateDirectory(tmpDirectory);

                // Copy create_token script
                const string createTokenScriptPath     = "./resources/scripts/create_token.py";
                var          createTokenScriptFilename = Path.GetFileName(createTokenScriptPath);
                File.Copy(Path.GetFullPath(createTokenScriptPath), Path.Combine(tmpDirectory, createTokenScriptFilename));

                const int    HassPort              = 8123;
                const string HassVersion           = "latest";
                const string hassConfigPath        = "./resources/config";
                const string tokenFilename         = "TOKEN";
                var          testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                                     .WithImage($"homeassistant/home-assistant:{HassVersion}")
                                                     .WithPortBinding(HassPort, assignRandomHostPort: true)
                                                     .WithExposedPort(HassPort)
                                                     .WithBindMount(Path.GetFullPath(hassConfigPath), "/config")
                                                     .WithBindMount(tmpDirectory, "/tmp")
                                                     .WithWaitStrategy(Wait.ForUnixContainer()
                                                                       .UntilPortIsAvailable(HassPort))
                                                     .WithEntrypoint("/bin/bash", "-c")
                                                     .WithCommand($"python3 /tmp/{createTokenScriptFilename} >/tmp/{tokenFilename} && /init");

                this.hassContainer = testcontainersBuilder.Build();
                await this.hassContainer.StartAsync();

                var mappedPort    = this.hassContainer.GetMappedPublicPort(HassPort);
                var hostTokenPath = Path.Combine(tmpDirectory, tokenFilename);
                var accessToken   = File.ReadLines(hostTokenPath).First();

                Environment.SetEnvironmentVariable(BaseHassWSApiTest.TestsInstanceBaseUrlVar, $"http://localhost:{mappedPort}");
                Environment.SetEnvironmentVariable(BaseHassWSApiTest.TestsAccessTokenVar, accessToken);
            }
        }
示例#17
0
        public Infra()
        {
            // Configure Host
            IHostBuilder hostBuilder = Program.CreateHostBuilder(null !);

            hostBuilder.UseEnvironment("test")
            .ConfigureWebHost(builder => { builder.UseTestServer(); });

            TestServerHost  = hostBuilder.Build();
            ServiceProvider = TestServerHost.Services;

            // Create external dependencies and run
            _dbTestContainer = BuildSqlServerTestContainer(ServiceProvider);
            Task dbRunTask = _dbTestContainer.StartAsync();

            Task.WaitAll(dbRunTask);

            // Run Test Server
            TestServerHost.Start();

            HttpClient = TestServerHost.GetTestClient();
        }
 public async Task InitializeAsync()
 {
     _container = await LaunchDatabaseContainerAsync();
 }
        private static async Task ShutdownDatabaseContainerAsync(TestcontainersContainer container)
        {
            await container.CleanUpAsync();

            await container.DisposeAsync();
        }
示例#20
0
 public async Task InitializeAsync()
 {
     _container = await LaunchMongoContainerAsync(Port);
 }
示例#21
0
 public Container(TestcontainersContainer container)
 {
     _container = container;
 }
示例#22
0
    private async Task ShutdownMongoContainerAsync(TestcontainersContainer container)
    {
        await container.CleanUpAsync();

        await container.DisposeAsync();
    }