// Path: src/test/java/scaffolding/Photocopier.java
// public class Photocopier {
// 
//     public static File sampleDir() {
//         return new File(separatorsToSystem("sample-apps"));
//     }
// 
//     public static File copySampleAppToTempDir(String sampleAppName) throws IOException {
//         File target = folderForSampleProject(sampleAppName);
//         copySampleAppToDir(sampleAppName, target);
//         return target;
//     }
// 
//     public static void copySampleAppToDir(String sampleAppName, File target) throws IOException {
//         String pathname = FilenameUtils.concat(fullPath(sampleDir()), sampleAppName);
//         File source = new File(pathname);
//         if (!source.isDirectory()) {
//             source = new File(separatorsToSystem("../") + pathname);
//         }
//         if (!source.isDirectory()) {
//             throw new RuntimeException("Could not find module " + sampleAppName + " at " + new File(pathname) + " nor " + fullPath(source));
//         }
//         FileUtils.copyDirectory(source, target);
//     }
// 
//     public static File folderForSampleProject(String moduleName) {
//         return new File(separatorsToSystem("target/samples/" + UUID.randomUUID() + "/" + moduleName));
//     }
// 
//     public static File tempFile(String name) throws IOException {
//         File file = new File(separatorsToSystem("target/temp/" + UUID.randomUUID() + "/" + name));
//         FileUtils.touch(file);
//         return file;
//     }
// }
// 
// Path: src/test/java/scaffolding/TestConfig.java
// public class TestConfig {
//     public static final Config config;
// 
//     static {
//         try {
//             config = Config.load(new String[]{"sample-config.properties"});
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static Map<String,String> testEnvVars(int port, String appName) throws IOException {
//         File tempDir = new File("target/testapp/" + appName + "/temp");
//         File dataDir = new File("target/testapp/" + appName + "/data/" + UUID.randomUUID());
//         FileUtils.forceMkdir(dataDir);
//         FileUtils.forceMkdir(tempDir);
//         return AppManager.createAppEnvVars(port, appName, dataDir, tempDir);
//     }
// }


import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.StringBuilderWriter;
import org.apache.commons.lang3.SystemUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import scaffolding.Photocopier;
import scaffolding.TestConfig;
import java.io.File;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
package com.danielflower.apprunner.runners;




public class GoLangRunnerTest {

    private static GoRunnerFactory goRunnerFactory;
    private StringBuilderWriter buildLog = new StringBuilderWriter();
    private StringBuilderWriter consoleLog = new StringBuilderWriter();

    @BeforeClass public static void ignoreTestIfNotSupported() throws Exception {
        Optional<GoRunnerFactory> goRunnerFactoryMaybe = GoRunnerFactory.createIfAvailable(TestConfig.config);
        assumeTrue("Skipping GO test because Go not detected", goRunnerFactoryMaybe.isPresent());
        assumeFalse("Skipping go tests on Windows because the firewall seems to block it", SystemUtils.IS_OS_WINDOWS);
        goRunnerFactory = goRunnerFactoryMaybe.get();
    }

    @Test
    public void canStartAndStopGoProjects() throws Exception {
        // doing it twice proves the port was cleaned up
        canStartAnGOProject(1, "golang");
        canStartAnGOProject(2, "golang");
    }

    @Test
    public void canStartAndStopGoProjectsWithGoModule() throws Exception {
        // doing it twice proves the port was cleaned up
        canStartAnGOProject(1, "golang-mod");
        canStartAnGOProject(2, "golang-mod");
    }

    @Test
    public void theVersionIsReported() {
        assertThat(goRunnerFactory.versionInfo(), containsString("go"));
    }

    private void canStartAnGOProject(int attempt, String appName) throws Exception {
        File projectRoot = Photocopier.folderForSampleProject("instances" + File.separator + appName);
// Path: src/test/java/scaffolding/Photocopier.java
// public class Photocopier {
// 
//     public static File sampleDir() {
//         return new File(separatorsToSystem("sample-apps"));
//     }
// 
//     public static File copySampleAppToTempDir(String sampleAppName) throws IOException {
//         File target = folderForSampleProject(sampleAppName);
//         copySampleAppToDir(sampleAppName, target);
//         return target;
//     }
// 
//     public static void copySampleAppToDir(String sampleAppName, File target) throws IOException {
//         String pathname = FilenameUtils.concat(fullPath(sampleDir()), sampleAppName);
//         File source = new File(pathname);
//         if (!source.isDirectory()) {
//             source = new File(separatorsToSystem("../") + pathname);
//         }
//         if (!source.isDirectory()) {
//             throw new RuntimeException("Could not find module " + sampleAppName + " at " + new File(pathname) + " nor " + fullPath(source));
//         }
//         FileUtils.copyDirectory(source, target);
//     }
// 
//     public static File folderForSampleProject(String moduleName) {
//         return new File(separatorsToSystem("target/samples/" + UUID.randomUUID() + "/" + moduleName));
//     }
// 
//     public static File tempFile(String name) throws IOException {
//         File file = new File(separatorsToSystem("target/temp/" + UUID.randomUUID() + "/" + name));
//         FileUtils.touch(file);
//         return file;
//     }
// }
// 
// Path: src/test/java/scaffolding/TestConfig.java
// public class TestConfig {
//     public static final Config config;
// 
//     static {
//         try {
//             config = Config.load(new String[]{"sample-config.properties"});
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static Map<String,String> testEnvVars(int port, String appName) throws IOException {
//         File tempDir = new File("target/testapp/" + appName + "/temp");
//         File dataDir = new File("target/testapp/" + appName + "/data/" + UUID.randomUUID());
//         FileUtils.forceMkdir(dataDir);
//         FileUtils.forceMkdir(tempDir);
//         return AppManager.createAppEnvVars(port, appName, dataDir, tempDir);
//     }
// }


// Path: src/test/java/com/danielflower/apprunner/runners/GoLangRunnerTest.java
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.StringBuilderWriter;
import org.apache.commons.lang3.SystemUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import scaffolding.Photocopier;
import scaffolding.TestConfig;
import java.io.File;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

package com.danielflower.apprunner.runners;




public class GoLangRunnerTest {

    private static GoRunnerFactory goRunnerFactory;
    private StringBuilderWriter buildLog = new StringBuilderWriter();
    private StringBuilderWriter consoleLog = new StringBuilderWriter();

    @BeforeClass public static void ignoreTestIfNotSupported() throws Exception {
        Optional<GoRunnerFactory> goRunnerFactoryMaybe = GoRunnerFactory.createIfAvailable(TestConfig.config);
        assumeTrue("Skipping GO test because Go not detected", goRunnerFactoryMaybe.isPresent());
        assumeFalse("Skipping go tests on Windows because the firewall seems to block it", SystemUtils.IS_OS_WINDOWS);
        goRunnerFactory = goRunnerFactoryMaybe.get();
    }

    @Test
    public void canStartAndStopGoProjects() throws Exception {
        // doing it twice proves the port was cleaned up
        canStartAnGOProject(1, "golang");
        canStartAnGOProject(2, "golang");
    }

    @Test
    public void canStartAndStopGoProjectsWithGoModule() throws Exception {
        // doing it twice proves the port was cleaned up
        canStartAnGOProject(1, "golang-mod");
        canStartAnGOProject(2, "golang-mod");
    }

    @Test
    public void theVersionIsReported() {
        assertThat(goRunnerFactory.versionInfo(), containsString("go"));
    }

    private void canStartAnGOProject(int attempt, String appName) throws Exception {
        File projectRoot = Photocopier.folderForSampleProject("instances" + File.separator + appName);
        FileUtils.copyDirectory(new File(Photocopier.sampleDir(), appName),