使用Scala的testContainers Postgres执行初始脚本
我正在尝试使用 testContainers-scala-postgresql
使用TestContainers,PostgreSQL和Scala旋转一些测试。我想在容器启动期间运行一个初始化脚本,以创建和填充表。
但是, com.dimafeng.testcontainers.postgresqlcontainer
type类型不包含 interscript
方法,该方法中存在于Java版本中。
在启动期间,我还有其他方法可以配置init脚本的执行吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用postgresqlcontainer.def,在其中可以通过InitscriptPath通过CommonjDbcParams:
You could use PostgreSQLContainer.Def, where are an ability to pass commonJdbcParams with initScriptPath:
Postgres Image可以选择“启动”,这是/docker-entrypoint-initdb.d )。
简而言之,
*。sql
,*。sql.gz
,或*。
/docker-endrypoint-initdb下的脚本。 D
在启动时执行。在Java版本中,您可以使用
withcopyfiletocontainer
方法,我认为Scala中应该有类似的东西吗?因此,类似:
如果您有更多文件,则将按词典顺序执行。
Postgres image has the option to init the database on start, here's the docs on DockerHub (look for the
/docker-entrypoint-initdb.d
).In short,
*.sql
,*.sql.gz
, or*.sh
scripts under/docker-entrypoint-initdb.d
are executed on startup.In the Java version you can use the
withCopyFileToContainer
method, I think something similar should be in Scala right?So something like:
And if you have more files, they will be executed in lexicographic order.