forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the problem that plugins without jar file may not be deleted (hal…
…o-dev#6334) /kind bug /area core /area plugin /milestone 2.18.x This PR checks if the plugin is already unloaded while getting dependents to fix the problem that plugins without jar file may not be deleted or not be enabled or disabled. Fixes halo-dev#6072 1. Try to move plugins folder to another folder 2. Restart Halo 3. Try to change state of plugins or delete plugins directly 4. See the result ```release-note 修复在没有插件文件的情况下可能无法删除插件的问题 ```
- Loading branch information
Showing
2 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
application/src/test/java/run/halo/app/plugin/HaloPluginManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package run.halo.app.plugin; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.github.zafarkhaja.semver.Version; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.pf4j.RuntimeMode; | ||
import org.springframework.context.ApplicationContext; | ||
import run.halo.app.infra.SystemVersionSupplier; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class HaloPluginManagerTest { | ||
|
||
@Mock | ||
PluginProperties pluginProperties; | ||
|
||
@Mock | ||
SystemVersionSupplier systemVersionSupplier; | ||
|
||
@Mock | ||
ApplicationContext rootContext; | ||
|
||
@InjectMocks | ||
HaloPluginManager pluginManager; | ||
|
||
@TempDir | ||
Path tempDir; | ||
|
||
@Test | ||
void shouldGetDependentsWhilePluginsNotResolved() throws Exception { | ||
when(pluginProperties.getRuntimeMode()).thenReturn(RuntimeMode.DEPLOYMENT); | ||
when(systemVersionSupplier.get()).thenReturn(Version.of(1, 2, 3)); | ||
pluginManager.afterPropertiesSet(); | ||
// if we don't invoke resolves | ||
var dependents = pluginManager.getDependents("fake-plugin"); | ||
assertTrue(dependents.isEmpty()); | ||
} | ||
|
||
@Test | ||
void shouldGetDependentsWhilePluginsResolved() throws Exception { | ||
when(pluginProperties.getRuntimeMode()).thenReturn(RuntimeMode.DEPLOYMENT); | ||
when(systemVersionSupplier.get()).thenReturn(Version.of(1, 2, 3)); | ||
pluginManager.afterPropertiesSet(); | ||
pluginManager.loadPlugins(); | ||
// if we don't invoke resolves | ||
var dependents = pluginManager.getDependents("fake-plugin"); | ||
assertTrue(dependents.isEmpty()); | ||
} | ||
|
||
|
||
} |