use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class FileConsoleTest method testShutDownCase.
@Test
public void testShutDownCase() throws Exception {
TestingConsole delegate = new TestingConsole();
FileConsole fileConsole = new FileConsole(delegate, file, Duration.ofSeconds(2));
ExecutorService exec = Executors.newFixedThreadPool(2);
Future<?> f1 = exec.submit(() -> {
Thread.sleep(1000);
fileConsole.close();
return null;
});
Future<?> f2 = exec.submit(() -> {
fileConsole.info("This is info");
Thread.sleep(2000);
fileConsole.warn("This is warning");
return null;
});
f1.get();
f2.get();
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class FileConsoleTest method runTest.
private void runTest(Path file) throws IOException {
TestingConsole delegate = new TestingConsole();
try (FileConsole fileConsole = new FileConsole(delegate, file, Duration.ZERO)) {
fileConsole.startupMessage("v1");
fileConsole.info("This is info");
fileConsole.warn("This is warning");
fileConsole.error("This is error");
fileConsole.verbose("This is verbose");
fileConsole.progress("This is progress");
}
List<String> lines = Files.readAllLines(file);
assertThat(lines).hasSize(6);
assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
assertThat(lines.get(1)).contains("INFO: This is info");
assertThat(lines.get(2)).contains("WARNING: This is warning");
assertThat(lines.get(3)).contains("ERROR: This is error");
assertThat(lines.get(4)).contains("VERBOSE: This is verbose");
assertThat(lines.get(5)).contains("PROGRESS: This is progress");
delegate.assertThat().matchesNext(MessageType.INFO, "Copybara source mover [(]Version: v1[)]").matchesNext(MessageType.INFO, "This is info").matchesNext(MessageType.WARNING, "This is warning").matchesNext(MessageType.ERROR, "This is error").matchesNext(MessageType.VERBOSE, "This is verbose").matchesNext(MessageType.PROGRESS, "This is progress");
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class FileConsoleTest method testFlushingFrequency_disabled.
@Test
public void testFlushingFrequency_disabled() throws Exception {
TestingConsole delegate = new TestingConsole();
try (FileConsole fileConsole = new FileConsole(delegate, file, Duration.ZERO)) {
fileConsole.startupMessage("v1");
fileConsole.info("This is info");
fileConsole.warn("This is warning");
fileConsole.error("This is error");
fileConsole.verbose("This is verbose");
fileConsole.progress("This is progress");
assertThat(Files.readAllLines(file)).isEmpty();
}
List<String> lines = Files.readAllLines(file);
assertThat(lines).hasSize(6);
assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
assertThat(lines.get(1)).contains("INFO: This is info");
assertThat(lines.get(2)).contains("WARNING: This is warning");
assertThat(lines.get(3)).contains("ERROR: This is error");
assertThat(lines.get(4)).contains("VERBOSE: This is verbose");
assertThat(lines.get(5)).contains("PROGRESS: This is progress");
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class FileConsoleTest method testFlushingFrequency.
@Test
public void testFlushingFrequency() throws Exception {
TestingConsole delegate = new TestingConsole();
try (FileConsole fileConsole = new FileConsole(delegate, file, Duration.ofSeconds(2))) {
fileConsole.startupMessage("v1");
fileConsole.info("This is info");
fileConsole.warn("This is warning");
assertThat(Files.readAllLines(file)).isEmpty();
Thread.sleep(3000);
fileConsole.error("This is error");
fileConsole.verbose("This is verbose");
List<String> lines = Files.readAllLines(file);
assertThat(lines).hasSize(3);
assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
assertThat(lines.get(1)).contains("INFO: This is info");
assertThat(lines.get(2)).contains("WARNING: This is warning");
fileConsole.progress("This is progress");
}
List<String> lines = Files.readAllLines(file);
assertThat(lines).hasSize(6);
assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
assertThat(lines.get(1)).contains("INFO: This is info");
assertThat(lines.get(2)).contains("WARNING: This is warning");
assertThat(lines.get(3)).contains("ERROR: This is error");
assertThat(lines.get(4)).contains("VERBOSE: This is verbose");
assertThat(lines.get(5)).contains("PROGRESS: This is progress");
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class GithubPrOriginTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("GithubPrDestinationTest-repoGitDir");
workdir = Files.createTempDirectory("workdir");
localHub = Files.createTempDirectory("localHub");
git("init", "--bare", repoGitDir.toString());
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
options.git = new TestGitOptions(localHub, () -> this.options.general, new Validator() {
@Override
public void validateFetch(String url, boolean prune, boolean force, Iterable<String> refspecs) {
for (String refspec : refspecs) {
// WARNING! This check is important. While using short names like
// 'master' in git fetch works for local git invocations, other
// implementations of GitRepository might have problems if we don't
// pass the whole reference.
assertThat(refspec).startsWith("refs/");
assertThat(refspec).contains(":refs/");
}
}
});
options.github = new GithubOptions(() -> options.general, options.git) {
@Override
public GithubApi getApi(String project) throws RepoException {
assertThat(project).isEqualTo(expectedProject);
return super.getApi(project);
}
@Override
protected HttpTransport getHttpTransport() {
return gitApiMockHttpTransport;
}
};
Path credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
options.git.credentialHelperStorePath = credentialsFile.toString();
skylark = new SkylarkTestExecutor(options, GitModule.class);
skylarkParser = new SkylarkParser(ImmutableSet.of(Core.class, Authoring.Module.class, FolderModule.class, GitModule.class));
}
Aggregations