package org.testcontainers.jdbc;

import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.testsupport.Flaky;
import org.testcontainers.testsupport.FlakyTestJUnit4RetryRule;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;

public class DatabaseDriverTmpfsTest {

    @Rule
    public FlakyTestJUnit4RetryRule retry = new FlakyTestJUnit4RetryRule();

    @Test
    @Flaky(githubIssueUrl = "https://github.com/testcontainers/testcontainers-java/issues/1687", reviewDate = "2020-03-01")
    public void tmpfs() throws IOException, InterruptedException, SQLException {
        final String jdbcUrl = "jdbc:tc:postgresql:9.6.8://hostname/databasename?TC_TMPFS=/testtmpfs:rw";
        try (Connection ignored = DriverManager.getConnection(jdbcUrl)) {

            JdbcDatabaseContainer<?> container = ContainerDatabaseDriver.getContainer(jdbcUrl);
            // check file doesn't exist
            String path = "/testtmpfs/test.file";
            Container.ExecResult execResult = container.execInContainer("ls", path);
            assertEquals("tmpfs inside container works fine", execResult.getStderr(),
                "ls: cannot access '/testtmpfs/test.file': No such file or directory\n");
            // touch && check file does exist
            container.execInContainer("touch", path);
            execResult = container.execInContainer("ls", path);
            assertEquals("tmpfs inside container works fine", execResult.getStdout(), path + "\n");
        }

    }


}

@@ -31,31 +31,8 @@
 c;%0A%0A
-import org.junit.Rule;%0A
 impo
@@ -162,145 +162,8 @@
 er;%0A
-import org.testcontainers.testsupport.Flaky;%0Aimport org.testcontainers.testsupport.FlakyTestJUnit4RetryRule;%0A%0Aimport java.io.IOException;
 %0Aimp
@@ -221,38 +221,8 @@
 ger;
-%0Aimport java.sql.SQLException;
 %0A%0Aim
@@ -293,16 +293,94 @@
 tEquals;
+%0Aimport static org.rnorth.visibleassertions.VisibleAssertions.assertNotEquals;
 %0A%0Apublic
@@ -418,20 +418,20 @@
 %7B%0A%0A    @
-Rule
+Test
 %0A    pub
@@ -438,277 +438,62 @@
 lic 
-FlakyTestJUnit4RetryRule retry = new FlakyTestJUnit4RetryRule();%0A%0A    @Test%0A    @Flaky(githubIssueUrl = %22https://github.com/testcontainers/testcontainers-java/issues/1687%22, reviewDate = %222020-03-01%22)%0A    public void tmpfs() throws IOException, InterruptedException, SQL
+void testDatabaseHasTmpFsViaConnectionString() throws 
 Exce
@@ -962,32 +962,35 @@
           assert
+Not
 Equals(%22tmpfs in
@@ -1008,132 +1008,74 @@
 ner 
-works fine%22, execResult.getStderr(),%0A                %22ls: cannot access '/testtmpfs/test.file': No such file or directory%5Cn%22
+doesn't have file that doesn't exist%22, 0, execResult.getExitCode()
 );%0A 
@@ -1290,56 +1290,62 @@
 ner 
-works fine%22, execResult.getStdout(), path + %22%5Cn%22
+has file that does exist%22, 0, execResult.getExitCode()
 );%0A 
@@ -1357,15 +1357,12 @@
   %7D%0A
-%0A
     %7D%0A
-%0A%0A
 %7D%0A

Fix flaky JDBC tmpfs test (#2646)