使用 testcontainer-go 时遇到问题

我正在试用页面示例https://github.com/testcontainers/testcontainer-go

package main


import (

    "context"

    "fmt"

    "net/http"

    "testing"


    testcontainer "github.com/testcontainers/testcontainer-go"

)


func TestNginxLatestReturn(t *testing.T) {

    ctx := context.Background()

    req := testcontainer.ContainerRequest{

        Image:        "nginx",

        ExposedPorts: []string{"80/tcp"},

    }

...

}

但是当我将代码放在文件main.go中<home>/go/src/my-sample并调用时go get,我只收到此错误:


#


 github.com/testcontainers/testcontainer-go

../github.com/testcontainers/testcontainer-go/docker.go:116:32: cannot use inspect.NetworkSettings.NetworkSettingsBase.Ports (type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortMap) as type "github.com/docker/go-connections/nat".PortMap in return argument

../github.com/testcontainers/testcontainer-go/docker.go:197:25: multiple-value uuid.NewV4() in single-value context

../github.com/testcontainers/testcontainer-go/docker.go:219:3: cannot use exposedPortSet (type map["github.com/docker/go-connections/nat".Port]struct {}) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortSet in field value

../github.com/testcontainers/testcontainer-go/docker.go:261:3: cannot use exposedPortMap (type map["github.com/docker/go-connections/nat".Port][]"github.com/docker/go-connections/nat".PortBinding) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortMap in field value

我究竟做错了什么?


智慧大石
浏览 95回答 1
1回答

MMTTMM

我也重现了这个问题,但我确实通过以下步骤构建并运行了测试:my_package在树之外创建一个目录$GOPATH。创建一个mypackage_test.go包含以下内容的文件:package mainimport (&nbsp; &nbsp; "testing"&nbsp; &nbsp; testcontainer "github.com/testcontainers/testcontainer-go")func testNginxLatestReturn(t *testing.T) {&nbsp; &nbsp; req := testcontainer.ContainerRequest{&nbsp; &nbsp; &nbsp; &nbsp; Image:&nbsp; &nbsp; &nbsp; &nbsp; "nginx",&nbsp; &nbsp; &nbsp; &nbsp; ExposedPorts: []string{"80/tcp"},&nbsp; &nbsp; }&nbsp; &nbsp; t.Log(req)}go mod init mypackagego test
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go