我刚刚将测试容器库从 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(不再支持 link )已被 Mounts 取代。 尝试在我的初始化脚本中替换相同的内容,但找不到它。
BindMounts: map[string]string{"/mountebank": path.Join(c.rootDir, "/test/stubs/mountebank")},
它是请求正文的一部分。尝试使用 testcontainers.ContainerMounts{}
等。
我错过了什么吗?
最佳答案
ContainerRequest
对象包含 ContainerMount
的列表对象,记录了
Source is typically either a GenericBindMountSource or a 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"),
}),
...
},
关于docker - GoLang postgres testcontainer 将 BindMounts 转换为 Mounts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72181947/