Home > Mobile >  GoLang postgres testcontainer convert BindMounts to Mounts
GoLang postgres testcontainer convert BindMounts to Mounts

Time:05-11

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?

CodePudding user response:

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"),
        }),
        ...
},
  • Related