Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
13 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
api/src/main/java/run/halo/app/infra/BackupRootGetter.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,14 @@ | ||
package run.halo.app.infra; | ||
|
||
import java.nio.file.Path; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Utility of getting backup root path. | ||
* | ||
* @author johnniang | ||
* @since 2.9.0 | ||
*/ | ||
public interface BackupRootGetter extends Supplier<Path> { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
application/src/main/java/run/halo/app/infra/DefaultBackupRootGetter.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,20 @@ | ||
package run.halo.app.infra; | ||
|
||
import java.nio.file.Path; | ||
import org.springframework.stereotype.Component; | ||
import run.halo.app.infra.properties.HaloProperties; | ||
|
||
@Component | ||
public class DefaultBackupRootGetter implements BackupRootGetter { | ||
|
||
private final HaloProperties haloProperties; | ||
|
||
public DefaultBackupRootGetter(HaloProperties haloProperties) { | ||
this.haloProperties = haloProperties; | ||
} | ||
|
||
@Override | ||
public Path get() { | ||
return haloProperties.getWorkDir().resolve("backups"); | ||
} | ||
} |
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
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
33 changes: 33 additions & 0 deletions
33
application/src/test/java/run/halo/app/infra/DefaultBackupRootGetterTest.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,33 @@ | ||
package run.halo.app.infra; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import run.halo.app.infra.properties.HaloProperties; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DefaultBackupRootGetterTest { | ||
|
||
@Mock | ||
HaloProperties haloProperties; | ||
|
||
@InjectMocks | ||
DefaultBackupRootGetter backupRootGetter; | ||
|
||
@Test | ||
void shouldGetBackupRootFromWorkDir() { | ||
when(haloProperties.getWorkDir()).thenReturn(Path.of("workdir")); | ||
var backupRoot = this.backupRootGetter.get(); | ||
assertEquals(Path.of("workdir", "backups"), backupRoot); | ||
verify(haloProperties).getWorkDir(); | ||
} | ||
|
||
|
||
} |
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