use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.
the class IndexBaseAndGitRepoJobTest method testCloneSucess.
public void testCloneSucess() throws IOException {
IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
File baseDir = new File(System.getProperty("java.io.tmpdir"));
File tempDir = new File(baseDir, "testIndexSucess");
if (tempDir.exists()) {
FileUtils.deleteDirectory(tempDir);
}
tempDir.mkdir();
String tempDirString = tempDir.toString();
assertFalse(gitRepoJob.checkCloneUpdateSucess(tempDirString));
gitRepoJob.createCloneUpdateSuccess(tempDirString);
assertTrue(gitRepoJob.checkCloneUpdateSucess(tempDirString));
gitRepoJob.deleteCloneUpdateSuccess(tempDirString);
assertFalse(gitRepoJob.checkCloneUpdateSucess(tempDirString));
}
use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.
the class IndexBaseAndGitRepoJobTest method testGetFileMd5.
public void testGetFileMd5() {
IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
gitRepoJob.getFileMd5("filedoesnotexist");
}
use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.
the class IndexBaseAndGitRepoJobTest method testMissingPathFilesNoLocations.
public void testMissingPathFilesNoLocations() {
IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
CodeSearcher codeSearcherMock = Mockito.mock(CodeSearcher.class);
when(codeSearcherMock.getRepoDocuments("testRepoName", 0)).thenReturn(new ArrayList<>());
gitRepoJob.cleanMissingPathFiles(codeSearcherMock, "testRepoName", new HashMap<String, String>());
verify(codeSearcherMock, times(1)).getRepoDocuments("testRepoName", 0);
}
use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.
the class IndexBaseAndGitRepoJobTest method testGetBlameFilePathWindows.
// No such thing as a windows path in the index, so should return empty
public void testGetBlameFilePathWindows() {
IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
String actual = gitRepoJob.getBlameFilePath("\\repo\\something\\test");
assertEquals("", actual);
}
use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.
the class EndToEndITCase method testEndToEndGitPath.
public void testEndToEndGitPath() throws IOException {
CodeSearcher cs = new CodeSearcher();
File directoryWithFiles = TestHelpers.createDirectoryWithFiles("EndToEndGitTest");
String result = this.runCommand(directoryWithFiles.toString(), this.GITPATH, "init", ".");
result = this.runCommand(directoryWithFiles.toString(), this.GITPATH, "add", ".");
result = this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"First commit\"");
IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
indexGitRepoJob.indexDocsByPath(Paths.get(directoryWithFiles.toString()), "ENDTOENDTEST", "", directoryWithFiles.toString(), false);
SearchResult searchResult = cs.search("endtoendtestfile", 0);
assertThat(searchResult.getCodeResultList().size()).isEqualTo(3);
CodeResult codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile1.php")).findFirst().get();
CodeResult codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile2.py")).findFirst().get();
CodeResult codeResult3 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile1");
assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile2");
assertThat(codeResult3.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
// Delete a single file
String codeId = searchResult.getCodeResultList().get(0).getCodeId();
Singleton.getCodeIndexer().deleteByCodeId(codeId);
searchResult = cs.search("endtoendtestfile".toLowerCase(), 0);
assertThat(searchResult.getCodeResultList().size()).isEqualTo(2);
// Delete file from disk then index to ensure it is removed from the index
File toDelete = new File(directoryWithFiles.toString() + "/EndToEndTestFile2.py");
toDelete.delete();
indexGitRepoJob.indexDocsByPath(Paths.get(directoryWithFiles.toString()), "ENDTOENDTEST", "", directoryWithFiles.toString(), true);
searchResult = cs.search("endtoendtestfile", 0);
assertThat(searchResult.getCodeResultList().size()).isEqualTo(2);
codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile1.php")).findFirst().get();
codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile1");
assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
Singleton.getCodeIndexer().deleteByReponame("ENDTOENDTEST");
searchResult = cs.search("endtoendtestfile".toLowerCase(), 0);
assertThat(searchResult.getCodeResultList().size()).isEqualTo(0);
}
Aggregations