Testing plugin action using testData, but no repository found
Hello. I am trying to test a plugin action that is only visible if there is git installed for a project. I created a directory in testdata that has mock git data (with configs, refs, etc.), and somewhere in my test I rename the mock git directory to .git in another temporary directory when setting up the test.
I tried using BasePlatformTestCase so that I can use configureByFile() to refer to the temporary directory. However, my tests fail because GitRepository.getRepositories() returns an empty list when using Git4Idea functions in my source code, resulting in null.
I don't know if I'm misunderstanding the documentation or Git4Idea source code, so I was wondering if anyone could help me with this.
Thanks in advance
Please sign in to leave a comment.
I'm sorry, but I couldn't find GitRepository.getRepositories() which you refer. Did you mean GitRepositoryManager.getRepositories()?
Can you share your code?
Hi Jakub,
My apologies, yes I meant to say GitRepositoryManager.getRepositories().
I'll try to simplify how my code looks at the moment:
MyAction.java
MyUtilFile.java
MyActionTest.java
Can you try, after renaming the GIT directory to .git, call the following method?
It is supposed to refresh the information about the repository.
Hi sorry for the late follow-up (timezones).
When running the following, repo is still null:
I also tried newGitDir.getAbsolutePath() to get the virtual file using findFileByPath. But not even with this a repo instance is defined. However, I can confirm that the renaming does work as intended. Here is how the path dst.getAbsolutePath() looks like: file:///Users/svorden/git/myproject/temp:/root
It's better to explicitly make sure that IDE knows about renamed directory, see VfsUtil.markDirtyAndRefresh().
Main issue is that test root needs to be registered in vcs mappings (the ones from "Settings | Version Control" tab).
This can be done using ProjectLevelVcsManager.getInstance(project).setDirectoryMappings(singletonList(new VcsDirectoryMapping(virtualFile.getPath(), GitVcs.NAME))).
See GitSingleRepoTest in IJ-community sources as an example.
Hi Aleksey,
By running the code you provided using ProjectLevelVcsManager, repo is no longer null. Thanks! This is how my code looks like:
I'm now facing an issue though when I run my test. I don't know if it's related to my test though and I'd like some of your input:
Memory leak might be caused by second createTempDirTestFixture call. Using 'myFixture.getTempDirPath()' should fix the issue.
Also, you're using in-memory mock VFS paths together with java.io.File. This is likely to cause issues.
UPD: It should not be an issue, as "temp:///" file system is disabled by default.