在我的中,我有一个依赖于MongoDb的部分,我必须对它进行测试。
我希望能够在本地和构建服务器上运行测试。
目前,我正在尝试这样做,并补充道
testCompile group: 'de.flapdoodle.embed', name: 'de.flapdoodle.embed.mongo', version: '2.2.0'
作为依赖。
这个包从mongodb.org下载mongo可执行文件,提取它们并在本地存储它们。虽然它在本地工作很有魅力,但它在构建服务器上肯定会失败,因为它不能访问远程站点。
因此,我想更改配置,使用已添加到项目回购中的工件回购中的可执行项,或者--如果有必要的话--。
一段有趣的代码似乎是de.flapdoodle.embed.mongo.config.DownloadConfigBuilder
EMBEDDED_MONGO_ARTIFACTS
可以使用。
私有静态类PlatformDependentDownloadPath实现IDownloadPath {@覆盖公共字符串getPath(分发){ if IDownloadPath{返回"https://downloads.mongodb.org/";}返回"https://fastdl.mongodb.org/";}
然后,在flapdoodle的文档中可以找到:
但是,这个downloadPath似乎并不是绝对的。
简要说明:
我需要如何构造我的下载镜像Autoconfiguration
发布于 2021-03-29 21:26:00
我知道这个问题提出已经有一段时间了,但也许会有所帮助。
我通过以下@Configuration (在您的测试包中)手动配置它。
@Configuration
public class EmbeddedMongoDBConfig {
@Bean
public IRuntimeConfig embeddedMongoRuntimeConfig() {
final Command command = Command.MongoD;
final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
.defaults(command)
.artifactStore(new ExtractedArtifactStoreBuilder()
.defaults(command)
.downloader(new Downloader())
.download(new DownloadConfigBuilder()
.downloadPath("http://host/path/to/mongodb/server/mongodb/3.5.5/")
.fileNaming(new UserTempNaming())
.downloadPrefix("")
.artifactStorePath(new PlatformTempDir())
.progressListener(new Slf4jProgressListener(log))
.userAgent("")
.packageResolver(new IPackageResolver() {
// this apparently is expected to return the name of the executable (in the download package)
@Override
public FileSet getFileSet(Distribution distribution) {
String filename = (distribution.getPlatform().isUnixLike()) ? "bin/mongod" : "bin/mongod.exe";
return FileSet.builder()
.addEntry(FileType.Executable, filename)
.build();
}
@Override
public ArchiveType getArchiveType(Distribution distribution) {
if(distribution.getPlatform().isUnixLike()) return ArchiveType.TGZ;
else return ArchiveType.ZIP;
}
// the path (appended to the download link above)
@Override
public String getPath(Distribution distribution) {
return (distribution.getPlatform().isUnixLike()) ? "mongodb-3.5.5-linux-x86_64.tgz" : "mongodb-3.5.5-win32-x86_64.zip";
}
})
.build())
.executableNaming(new UserTempNaming())
.build())
.build();
return runtimeConfig;
}
发布于 2021-11-01 10:14:46
您只需在构建服务器上的构建管道中提供要测试的mongodb的发行版
Flapdoodle嵌入式Mongodb将将相关的mongoDB发行版下载到名为“.embedmongo”的用户主目录中。
例如:
.embedmongo/osx/mongodb-osx-x86_64-3.2.22.tgz‘
如果您从https://www.mongodb.com/try/download/community下载所需的发行版,并将其放在相关OS路径下的.embedmongo目录中。
然后,可以使用单独的Spring指定在spring应用程序测试属性中下载的版本。
spring:
mongodb:
embedded:
version: "3.2.22"
Embedded mongo将获取该发行版以提取并运行。
这种方式为我们解决了同样的问题。我确实希望您能够为您想要在spring.mongodb.embed属性中使用的压缩mongodb发行版提供一个绝对路径,以便它可以包含在src代码中。
https://stackoverflow.com/questions/63613461
复制相似问题