【发布时间】:2021-01-28 03:42:39
【问题描述】:
我可以使用下面的 sn-p 启动 mongo 图像,插入和读取数据。类似于 testcontainers.org 上的 redis 示例。
private static final int MONGO_PORT = 27017;
@ClassRule
public static MongoDBContainer mongo = new MongoDBContainer("mongo:3.2.4")
.withExposedPorts(MONGO_PORT);
默认情况下,mongo 没有凭据,但我正在寻找一种设置凭据的方法,以便我的应用程序的 MongoClient 可以从系统属性中获取用户/密码并正确连接。我尝试使用以下内容添加 root 用户/密码,但没有正确设置凭据。
@ClassRule
public static MongoDBContainer mongo = new MongoDBContainer("mongo:3.2.4")
.withExposedPorts(MONGO_PORT)
.withEnv("MONGO_INITDB_ROOT_USERNAME", "admin")
.withEnv("MONGO_INITDB_ROOT_PASSWORD", "admin");
我的问题是:如何使用用户名和密码启动测试容器,以允许我的应用在使用wiremock 进行集成测试期间连接到它。
【问题讨论】: