public void DatabaseIntegratedTest(string dbTechnology) { bool isUnderContainer = (System.Environment.OSVersion.Platform == PlatformID.Unix); string buildTag = Environment.GetEnvironmentVariable("BUILD_TAG") ?? "jenkins-oragon-oragon-github-Oragon.Contexts-LOCAL-1"; Oragon.Spring.Context.Support.XmlApplicationContext context = new Oragon.Spring.Context.Support.XmlApplicationContext("assembly://Oragon.Context.Tests/Oragon.Context.Tests.Integrated/DatabaseIntegrationTests.docker.xml"); Skip.IfNot(context.ContainsObject($"{dbTechnology}.CreateContainerParameters"), "Has no configuration about " + dbTechnology); TimeSpan dockerDefaultTimeout = context.GetObject <TimeSpan>($"{dbTechnology}.DefaultTimeout"); int getLogsRetryCount = context.GetObject <int>($"{dbTechnology}.GetLogsRetryCount"); string textTofound = context.GetObject <string>($"{dbTechnology}.ExpectedText"); TimeSpan getLogsWaitTime = context.GetObject <TimeSpan>($"{dbTechnology}.GetLogsWaitTime"); CreateContainerParameters createContainerParameters = context.GetObject <CreateContainerParameters>($"{dbTechnology}.CreateContainerParameters"); ContainerStartParameters containerStartParameters = context.GetObject <ContainerStartParameters>($"{dbTechnology}.ContainerStartParameters"); ContainerLogsParameters containerLogsParameters = context.GetObject <ContainerLogsParameters>($"{dbTechnology}.ContainerLogsParameters"); //Convention - If runnig outside docker, need expose port to perform the test createContainerParameters.HostConfig.PublishAllPorts = !isUnderContainer; using (DockerClient docker = new DockerClientConfiguration(this.GetEndpoint()).CreateClient()) { //testing connectivity docker.DefaultTimeout = dockerDefaultTimeout; using (NetworkManager network = new NetworkManager(docker)) { network.Create(buildTag); using (ContainerManager container = new ContainerManager(docker)) { container.Create(createContainerParameters); if (container.Start(containerStartParameters)) { network.Connect(container, dbTechnology); container.WaitUntilTextFoundInLog(containerLogsParameters, textTofound, 10, getLogsWaitTime); ContainerInspectResponse containerInfo = container.Inspect(); string portKey = createContainerParameters.ExposedPorts.Keys.Single(); string dbPort, dbHostname; ContainerManager jenkinsTestContainer = null; if (!isUnderContainer) { dbPort = containerInfo.NetworkSettings.Ports[portKey].Single().HostPort; dbHostname = "127.0.0.1"; } else { jenkinsTestContainer = ContainerManager.GetCurrent(docker) ?? throw new InvalidOperationException("ContainerManager.GetCurrent result nothing"); network.Connect(jenkinsTestContainer, "jenkins_worker"); dbPort = portKey.Split('/', StringSplitOptions.RemoveEmptyEntries).First(); dbHostname = dbTechnology; } try { this.DatabaseIntegratedTestInternal(dbTechnology, dbHostname, dbPort); } finally { if (jenkinsTestContainer != null) { network.Disconnect(jenkinsTestContainer); } } } } } } }