gpt4 book ai didi

使用 testcontainer-go 时遇到问题

转载 作者:数据小太阳 更新时间:2023-10-29 03:21:00 25 4
gpt4 key购买 nike

我正在试用 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

我做错了什么?

最佳答案

我也重现了这个问题,但我确实通过以下步骤构建并运行了测试:

  1. $GOPATH 树之外创建一个 my_package 目录。
  2. 创建一个包含以下内容的 mypackage_test.go 文件:

    package main

    import (
    "testing"

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

    func testNginxLatestReturn(t *testing.T) {
    req := testcontainer.ContainerRequest{
    Image: "nginx",
    ExposedPorts: []string{"80/tcp"},
    }
    t.Log(req)
    }
  3. go mod init mypackage

  4. 去测试

关于使用 testcontainer-go 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54007888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com