英文:
GoLang postgres testcontainer convert BindMounts to Mounts
问题
我刚刚将测试容器库从github.com/testcontainers/testcontainers-go v0.12.0
升级到github.com/testcontainers/testcontainers-go v0.13.0
。之前我创建请求的方式如下:
ContainerRequest: testcontainers.ContainerRequest{
Image: mountebankImage,
Name: uuid.New().String(),
ExposedPorts: []string{mountebankExposedPort},
BindMounts: map[string]string{"/mountebank": path.Join(c.rootDir, "/test/stubs/mountebank")},
Entrypoint: []string{"mb", "start", "--configfile", "/mountebank/imposters.ejs"},
Networks: []string{c.network.Name},
}
在最新版本的测试容器库中,不再支持BindMounts(链接1)。我尝试在我的初始化脚本中替换它,但是找不到替代方法。
BindMounts: map[string]string{"/mountebank": path.Join(c.rootDir, "/test/stubs/mountebank")},
这是请求体的一部分。我尝试了testcontainers.ContainerMounts{}
等方法,但没有成功。
我有什么遗漏吗?
英文:
I have just upgraded the test container lib from github.com/testcontainers/testcontainers-go v0.12.0
to github.com/testcontainers/testcontainers-go v0.13.0
previously this is the way I was creating a request
ContainerRequest: testcontainers.ContainerRequest{
Image: mountebankImage,
Name: uuid.New().String(),
ExposedPorts: []string{mountebankExposedPort},
BindMounts: map[string]string{"/mountebank": path.Join(c.rootDir, "/test/stubs/mountebank")},
Entrypoint: []string{"mb", "start", "--configfile", "/mountebank/imposters.ejs"},
Networks: []string{c.network.Name},
In the recent version of the test container library, BindMounts(not supported anymore link) got replaced by Mounts.
Tried replacing the same in my init script however not able to find it.
BindMounts: map[string]string{"/mountebank": path.Join(c.rootDir, "/test/stubs/mountebank")},
its a part of request body. Tried with testcontainers.ContainerMounts{}
etc.
Am I missing something?
答案1
得分: 4
ContainerRequest
对象包含一个 ContainerMount
对象的列表,这些对象记录了
> 源通常是 GenericBindMountSource
或 GenericVolumeMountSource
GenericBindMountSource
只是命名了一个主机路径。如果需要高级选项,也可以使用 DockerBindMountSource
。
因此,您应该能够将 BindMounts:
参数替换为 Mounts:
ContainerRequest: testcontainers.ContainerRequest{
Mounts: testcontainers.Mounts(testcontainers.ContainerMount{
Source: testcontainers.GenericBindMountSource{
HostPath: path.Join(c.rootDir, "/test/stubs/mountebank"),
},
Target: testcontainers.ContainerMountTarget("/mountebank"),
}),
...
},
英文:
The ContainerRequest
object contains a list of ContainerMount
objects, which document that
> Source is typically either a GenericBindMountSource or a GenericVolumeMountSource
GenericBindMountSource
just names a host path. You could also use a DockerBindMountSource
if you needed advanced options.
So you should be able to replace that BindMounts:
parameter with Mounts:
ContainerRequest: testcontainers.ContainerRequest{
Mounts: testcontainers.Mounts(testcontainers.ContainerMount{
Source: testcontainers.GenericBindMountSource{
HostPath: path.Join(c.rootDir, "/test/stubs/mountebank"),
},
Target: testcontainers.ContainerMountTarget("/mountebank"),
}),
...
},
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论